Forum Discussion

mlang760's avatar
mlang760
Copper Contributor
Aug 08, 2023

I'm having trouble creating a MEDIAN(IF(AND function in excel.

I'm trying to create a function that returns a median of an array when two criterion are met. The function works if I do a MEDIAN(IF( statement with one criterion. However, as soon as I change it to MEDIAN(IF(AND( the function returns 0. I tried Control + Shift + Enter, but it still does not work. I have provided an example below. 

The formula for cell D1 is =MEDIAN(IF(B2:B9="a",C2:C9)), which returns the correct Median for the list.

 

The formula for cell D3 is =MEDIAN(IF(AND(B2:B9="a",A2:A9=6),C2:C9)), which returns the incorrect Median for the list. 

 

6a13
6f78 
6a30
6g45 
6h9 
6a1 
6a34 
6a5 

 

7 Replies

  • mlang760 

    =MEDIAN(IF((B2:B9="a")*(A2:A9=6),C2:C9))

    You can try this formula. Enter the formula with ctrl+shift+enter if you don't work with Office 365 or Excel 2021.

      • mtarler's avatar
        mtarler
        Silver Contributor
        Is it possible those 'number' 6 cells are really text? I notice they are left formatted (default for text) instead of right formatted (default for numbers), but maybe you forced it that way.
        FYI the reasoning to use (expression)*(expression) instead of AND(expression, expression) is because the AND will be applied to the entire combined range of ALL values while the multiplication will be applied through the index array.

Resources