+ Reply to Thread
Results 1 to 11 of 11

Median IF formula query please

  1. #1
    Registered User
    Join Date
    02-03-2024
    Location
    Nottingham, England
    MS-Off Ver
    Excel for Mac 365
    Posts
    4

    Question Median IF formula query please

    Hi
    I have a large data set looking at patient outcomes (length of stay in hospital) and want to break it down by month.
    I am trying to calculate the median of a column (column I - the number of days in hospital) based on the text in a different column (column D - month e.g. Feb-24, Jan-24, Dec-23 etc)
    I have tried to use "=MEDIAN(IF(D:D="Feb-24", I:I))" but I just get a #NUM error!
    Can anyone please tell me what I am doing wrong?
    Thanks in advance!

  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. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,471

    Re: Median IF formula query please

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook (yellow banner: HOW TO ATTACH YOUR SAMPLE WORKBOOK). Screenshots are of little practical use as we cannot manipulate them.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    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 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,207

    Re: Median IF formula query please

    If column D contains real dates, it won't work 'cos "feb-24" is text that looks like a date. NEVER use whole column refs with this type of formula as Excel will (slowly) calculate every one of the 1,000,000 rows it can take.
    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

  4. #4
    Registered User
    Join Date
    02-03-2024
    Location
    Nottingham, England
    MS-Off Ver
    Excel for Mac 365
    Posts
    4

    Re: Median IF formula query please

    Thank you very much Glenn - the column D does not contain real dates but does contain "Feb-24" or "Jan-24" as text

    Does that make a difference? I'm a bit of an Excel amateur...

  5. #5
    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,207

    Re: Median IF formula query please

    OK. So post a SMALL sample sheet (anonymised) with 10-20 rows of data

  6. #6
    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,207

    Re: Median IF formula query please

    I would probably use AGGREGATE:

    =AGGREGATE(16,6,I1:I10/(D1:D10="Feb-24"),0.5)

    BUT... I bet you that the column D data ARE dates... as your formula DOES work!!
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-03-2024
    Location
    Nottingham, England
    MS-Off Ver
    Excel for Mac 365
    Posts
    4

    Re: Median IF formula query please

    Ok - please see a sample attached

    I have just copied and pasted a few lines from the master spreadsheet... I am trying to find a simple formula to fill in the boxes highlighted in yellow

    Thank you so much for your help
    Attached Files Attached Files

  8. #8
    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,207

    Re: Median IF formula query please

    The dates in Col D ARE real dates. The value in col I are ALSO real dates. Formatting them to LOOK lile MMM-YY does not change the fact that they ARE dates.

    See filer. I changed BOTH sets of formulae. AVERAGE is OK with whole columns MEDIAN-IF is NOT.
    Attached Files Attached Files

  9. #9
    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. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,471

    Re: Median IF formula query please

    They ARE indeed dates!!!

  10. #10
    Registered User
    Join Date
    02-03-2024
    Location
    Nottingham, England
    MS-Off Ver
    Excel for Mac 365
    Posts
    4

    Re: Median IF formula query please

    You are both absolutely amazing

    Many thanks to you both

    Ben

  11. #11
    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. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,471

    Re: Median IF formula query please

    Try:

    =MEDIAN(FILTER($I$2:$I$20,$D$2:$D$20=L2))

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    L
    M
    N
    1
    Month Mean LOS Median LOS
    2
    Aug-23
    1.25
    1
    3
    Sep-23
    1
    1
    4
    Oct-23
    2.71428571
    2
    5
    Nov-23
    1.5
    1.5
    Sheet: Sheet1

+ 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. [SOLVED] Median if formula
    By RafaelF17 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-26-2018, 08:21 AM
  2. Replies: 2
    Last Post: 04-26-2017, 11:28 AM
  3. Replies: 8
    Last Post: 08-09-2016, 12:50 AM
  4. [SOLVED] Using Median IF to calculate the median for a specific criteria
    By boynejs in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-20-2014, 01:50 AM
  5. Using Median to get the median of seconds per day per checkpoint
    By dodgerpixie in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-16-2014, 03:38 AM
  6. Median Indirect: Find median in range and bring back adjacent cells
    By Keelin in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 06-27-2014, 08:31 AM
  7. [SOLVED] Median Ifs, need to find median $ amount per deal for each year
    By xenomorph8472 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-13-2012, 02:01 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