+ Reply to Thread
Results 1 to 21 of 21

Excel Median IF Array Formula

  1. #1
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Excel Median IF Array Formula

    Hi,

    I am doing the formula below and it seems to be working for 1 condition but not for the other 3. Everything is the same in the formula excel the rows that are changing when dragging the formula. Please help.

    =IFERROR(MEDIAN(IF($A$7:$A$85=$A90,IF($B$7:$B$85=$B90,D$7:D$85))),0)

    Thanks,
    JK
    Last edited by JKBR; 12-09-2020 at 07:29 PM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,875

    Re: Excel Median IF Array Formula

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Excel Median IF Array Formula

    What do you mean by not working? Returns an error value (unlikely given IFERROR)? Returns 0 when it shouldn't? Returns the wrong value?

    Are you entering this formula as an array formula, holding down [Ctrl] and [Shift] keys before pressing [Enter]?

  4. #4
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Re: Excel Median IF Array Formula

    Thank you for the quick response.

    I am doing contorl+Shift+Enter to calculate on row 86 thru 89. It's working on row 86 but not on the other 3 rows. I attached the report to my original post.

    Thank you.
    Last edited by JKBR; 12-03-2020 at 02:06 AM.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,875

    Re: Excel Median IF Array Formula

    There is nothing on those rows, so nothing to troubleshoot ...

    Again, please define "not working".

    The formula has been entered as an array formula ONLY on the first row of the table at the bottom. You need to do that before dragging down, however it won't change the results.
    Last edited by AliGW; 12-03-2020 at 02:08 AM.

  6. #6
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Re: Excel Median IF Array Formula

    Sorry, I updated the row numbers. I am using the formulas on rows 86 thru 89 and column D thru Y.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,875

    Re: Excel Median IF Array Formula

    Is there a reason why you have ignored the request to define "not working" twice now? Until you answer this, we can't help. Which results do you think are incorrect and why, and what do you think they should be?

    The formula has been entered as an array formula ONLY on the first row of the table at the bottom. You need to do that before dragging down, however it won't change the results.

  8. #8
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Excel Median IF Array Formula

    Your row 86 formulas are array formulas, but your formulas in rows 87 to 89 aren't.

  9. #9
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Re: Excel Median IF Array Formula

    Hi,

    Even after I change them to array formulas, it returns no values.

  10. #10
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Re: Excel Median IF Array Formula

    I am calculating median by month based on conditions from A86 thru B89. After using the array formulas, I am only see the median being calculated for row 86 and not for the other 3 rows. There should be values in majority of the cells for row 87 thru 89 as there is data to calculate the median.

  11. #11
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Excel Median IF Array Formula

    Dunno, it seems to work for me.

    ADDED: note the conditional counts I added below the array formulas. When there are 0s, the corresponding array formulas should return - to indicate no median because no numbers from which to calculate a median.
    Attached Files Attached Files
    Last edited by hrlngrv; 12-03-2020 at 02:43 AM. Reason: addendum

  12. #12
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Re: Excel Median IF Array Formula

    Thanks for doing the calc. When I do the same calculation on my computer, I return to same result as before. I can't see what you doing differently in your calculations.
    Last edited by JKBR; 12-09-2020 at 07:30 PM.

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Excel Median IF Array Formula

    It looks to me as though MEDIAN IF behaves differently to MEDIAN. Median is happy to ignore blank cells. However, Median-IF converts the blanks to zeros. So.... when you have 5 potential matching values: 0, 0, 0, 1, 3 the median is... zero.

    So, add another nested IF to select values >0:

    =IFERROR(MEDIAN(IF(($A$5:$A$80=$A86)*($B$5:$B$80=$B86)*(D$5:D$80>0),D$5:D$80,"")),0)

    You will probably have to array-enter this formula (Excel 2016).
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  14. #14
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,782

    Re: Excel Median IF Array Formula

    D86=IFERROR(AGGREGATE(16,6,D$5:D$80/($A$5:$A$80=$A86)/($B$5:$B$80=$B86)/(D$5:D$80>0),0.5),0)

    copy across and down

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Excel Median IF Array Formula

    That didn't occur to me, Caracalla. Nice one.

    JKBR: use Caracalla's solution: no array entry required.

  16. #16
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,782

    Re: Excel Median IF Array Formula

    Thanks Glenn

    Median with Aggregate Tutorial

    https://www.youtube.com/watch?v=zPgu...nel=ExcelIsFun

  17. #17
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Excel Median IF Array Formula

    My fault for using LibreOffice Calc to test this.

    Interesting that LibreOffice Calc preserves the blank values in D5:D80 in nested IF calls.

  18. #18
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Excel Median IF Array Formula

    This works because you're using PERCENTILE.INC.

    Seems odd to me that for D87,

    =AGGREGATE(12,6,D$5:D$80/($A$5:$A$80=$A87)/($B$5:$B$80=$B87)/ISNUMBER(D$5:D$80))

    produces a #VALUE! error, but enter

    =D$5:D$80/($A$5:$A$80=$A87)/($B$5:$B$80=$B87)/ISNUMBER(D$5:D$80)

    in D105:D180, and =AGGREGATE(12,6,D$105:D$180) generates the same result as your formula would. For me, that calls into question the quality of the implementation of AGGREGATE's MEDIAN subfunction, which in turn calls into question the overall quality of the implementation of AGGREGATE. From a different perspective, why bother including a MEDIAN subfunction if it's not robust.

  19. #19
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Excel Median IF Array Formula

    Sorry. I used LibreOffice Calc, and simple array formulas worked in it. I hadn't realized that Calc and Excel differ in this respect.

  20. #20
    Registered User
    Join Date
    12-03-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    8

    Re: Excel Median IF Array Formula

    Thank you all for your help.

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,875

    Re: Excel Median IF Array Formula

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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 Array Formula ignoring Blank Data
    By branpugh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-09-2019, 06:46 AM
  2. Replies: 2
    Last Post: 04-26-2017, 11:28 AM
  3. [SOLVED] Can Median() be put in an Array Formula?
    By MarvinP in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-06-2015, 07:27 PM
  4. Median of an Array
    By cdesantis01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2014, 01:18 AM
  5. Median of an Array
    By cdesantis01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2014, 11:59 PM
  6. [SOLVED] Median with two If statements in an array formula
    By Debbie Thomson in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-27-2013, 09:39 PM
  7. [SOLVED] Median IF OR array formula
    By alex_shin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-13-2013, 09:26 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