+ Reply to Thread
Results 1 to 3 of 3

Need help with array function using MEDIAN and nested IF with boolean AND

Hybrid View

  1. #1
    Registered User
    Join Date
    04-10-2013
    Location
    US
    MS-Off Ver
    Excel 2013
    Posts
    2

    Need help with array function using MEDIAN and nested IF with boolean AND

    Hello!

    I could really use a hand with a frustrating set of formulas. Here's the setup. I have tabular data, such as:

    Col A Col B Col C
    Name Type Time
    Bob Incident 30
    Susan Request 10
    Bob Incident 20
    Dan Other 40

    on a sheet called "TT Data." There are a few sets of calculations I need to perform. One is to calculate the Average and Median Time for all rows with Type "Incident". This I have been able to get, with the following formulas:
    =AVERAGEIF('TT Data'!B1:B50000, "=Incident", 'TT Data'!C1:C50000)
    {=MEDIAN(IF('TT Data'!B1:B50000="Incident",'TT Data'C1:C50000))}

    So far so good (hopefully those formula are correct!). Now things get a little trickier, as I need to find the Average and Median Time for all rows that are Type “Incident” and Name “Bob”
    Averageifs seems to work OK:

    =AVERAGEIFS('TT Data'!C1:C50000,'TT Data'!B1:B50000,"=Incident",'TT Data'!A1:A50000,"=Bob" )

    I’m running into trouble trying to use a logical AND operation in the array Median/nested IF function. Here is the formula I’m using:

    {=MEDIAN(IF(AND('TT Data'!B1:B50000="Incident",'TT Data'!A1:A50000="Bob"),'TTR= Data'!C1:C50000))}

    Excel accepts the formula, and spits out a total, but I know it’s incorrect. Looking further, it appears that as soon as it encounters a row that does not meet the criteria, the total is always zero. To test, I limited the range to one that I knew included only those that meet the criteria, and the median result was correct. Why does this happen? Is there a better way to “AND” these criteria together?

    Thank you very much for any advice!
    Last edited by account-ant; 04-10-2013 at 04:52 PM. Reason: had a followup question

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Need help with array function using MEDIAN and nested IF with boolean AND

    Try nested IFs instead of AND

    {=MEDIAN(IF('TT Data'!B1:B50000="Incident",IF('TT Data'!A1:A50000="Bob",'TTR= Data'!C1:C50000))}
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    04-10-2013
    Location
    US
    MS-Off Ver
    Excel 2013
    Posts
    2

    Re: Need help with array function using MEDIAN and nested IF with boolean AND

    THAT WORKED!!!! Thank you so much!

    I do have a follow up question. It seems that the function above (and others using IF functions) take into account empty cells, which skew the results. The ones just using AVERAGEIFS do not. Is that correct?

    I use the Data sheet repeatedly, pasting in new datasets frequently. There can be up to 50000 rows, but most often less. That's why I set the upper range to 50000. If empty cells are indeed skewing the calculations, how could I add some additional logic to skip any empty rows/cells in the range?

    Thanks in advance!

    EDIT: Clarification--sometimes I need to total items that are from Bob but NOT Type "Incident", so I use the <> operator instead. This is where I run into the empty cells issue, as <>Incident includes fields that are empty, apparently. Example:

    {=MEDIAN(IF('TT Data'!B1:B50000<>"Incident",IF('TT Data'!A1:A50000="Bob",'TTR= Data'!C1:C50000))}
    Last edited by account-ant; 04-10-2013 at 04:52 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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