+ Reply to Thread
Results 1 to 13 of 13

Calculate Median with multiple conditions

  1. #1
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Calculate Median with multiple conditions

    Hi,

    I need help with a formula. I have a big table where i need to calculate the median with multiple conditions. Please see attached file.
    Attached Files Attached Files

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: Calculate Median with multiple conditions

    hi there. you need to change the cells in H5 and I5 to show just the Type like in Column C. just "A" and "B". then perhaps this array formula in cell H6:
    =MEDIAN(IF(Tabell1[Fruit]=$G6,IF(Tabell1[Type]=H$5,Tabell1[Value])))
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    otherwise:
    =MEDIAN(IF(Tabell1[Fruit]=$G6,IF(Tabell1[Type]=SUBSTITUTE(H$5,"Type ",""),Tabell1[Value])))

    do also consider to input the desired results so that we don't have to second-guess if what we are doing is correct or not. you may look at my signature to upload an eg that is easier to understand.
    Attached Files Attached Files

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  3. #3
    Valued Forum Contributor than_gold's Avatar
    Join Date
    10-17-2017
    Location
    Coimbatore India
    MS-Off Ver
    Office 365
    Posts
    646

    Re: Calculate Median with multiple conditions

    Hello Masun,
    You can use Averageifs function.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Please refer attached excel for more clsrification.
    Attached Files Attached Files
    Regards,
    Thangavel D

    Appreciate the help? CLICK *

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Calculate Median with multiple conditions

    you can do that with PowerQuery add-in for Ex2010
    see attached file
    Attached Files Attached Files

  5. #5
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: Calculate Median with multiple conditions

    @sandy:
    i tried using the PowerQuery too. and i got the same answers as yours and they don't seem right. Orange for Type A if you filter the Table is:
    13
    34
    14
    22

    in ascending order would be:
    13
    14
    22
    34

    Median would be the average of 14 and 22; 18. the answer we get from Power Query is 14. not sure how it derived it. but it seems like for banan type B, and Apple Type B, Power Query took the 2nd number if it has 4 numbers in total instead of averaging it.

    ps: googled but forgot to read it before i posted. seems like a bug
    https://www.myonlinetraininghub.com/...ng-power-query

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Calculate Median with multiple conditions

    Because PQ Median treat blank values as 0 (not null)
    see attached file and try with/without zero

    because OP didn't show what he want to achieve I set simplest way

    Edit: I can calculate median for each product separately then join it to one table with null instead of 0
    Attached Files Attached Files
    Last edited by sandy666; 11-17-2017 at 05:41 AM.

  7. #7
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Calculate Median with multiple conditions

    Change Cell H5 to "A" and try this formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Calculate Median with multiple conditions

    Should be ok now
    PQ/PPT
    Attached Files Attached Files
    Last edited by sandy666; 11-17-2017 at 03:19 PM. Reason: little update

  9. #9
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Calculate Median with multiple conditions

    Hi!

    Thanks for all the help!

    I was wondering how i construct the formula if i need the median for both apple and orange for example. I have tried to put in the AND-function but have not succeeded. I have attached a file with the desired output. Hope you can help me!
    Attached Files Attached Files

  10. #10
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Calculate Median with multiple conditions

    Try This formula in H25 and copy to H25:M27
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    See the file
    Attached Files Attached Files

  11. #11
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: Calculate Median with multiple conditions

    i suggest you don't label the cell like you did in G15:G17. it is possible but difficult for the formula to pick it up. for what you did in G20:G22, add in the 2nd fruit in H20:H22
    Orange
    Apple
    Banana

    Ensure I19:J19 has the Type too; A. B.

    then in I20:
    =MEDIAN(IF((Tabell1[Fruit]=$G20)+(Tabell1[Fruit]=$H20),IF(Tabell1[Type]=I$19,Tabell1[Value])))

    ps: it's also good to try the solutions or acknowledge the efforts of other members who chipped in. i think Jose's AGGREGATE formula might work faster. but i hardly give AGGREGATE solutions as they are only available from Excel 2010 onwards. it will fail if you send it to someone else with lower version.
    sandy's solution should be interesting too. tedious at the start but easier to maintain later. calculates faster. again, only available from Excel 2010 onwards

  12. #12
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Calculate Median with multiple conditions

    Hi,

    Thank you very much! All of you! It is truly amazing with all the competence and willingness to help!

  13. #13
    Valued Forum Contributor than_gold's Avatar
    Join Date
    10-17-2017
    Location
    Coimbatore India
    MS-Off Ver
    Office 365
    Posts
    646

    Re: Calculate Median with multiple conditions

    Quote Originally Posted by Masun View Post
    Hi,

    Thank you very much! All of you! It is truly amazing with all the competence and willingness to help!
    Good to hear that you got answer for your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MEDIAN with multiple conditions
    By aarona in forum Excel General
    Replies: 3
    Last Post: 02-01-2017, 10:42 PM
  2. calculate a MEDIAN using multiple criteria?
    By MetricsShiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  3. calculate a MEDIAN using multiple criteria?
    By MetricsShiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 PM
  4. calculate a MEDIAN using multiple criteria?
    By MetricsShiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 PM
  5. calculate a MEDIAN using multiple criteria?
    By MetricsShiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  6. calculate a MEDIAN using multiple criteria?
    By MetricsShiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  7. calculate a MEDIAN using multiple criteria?
    By MetricsShiva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1