To calculate a conditional median based on one or more criteria you can use an array formula that uses the MEDIAN and IF functions together. In the example shown, the formula in F5 is:


where "group" is the named range B5:B14, and "data" is the named range C5:C14.

Note: this is an array formula and must be entered with control + shift + enter.

Generic formula



The MEDIAN function has no built-in way to apply criteria. Given a range, it will return the MEDIAN (middle) number in that range.

To apply criteria, we use the IF function inside MEDIAN to "filter" values. In this example, the IF function filters by group like this:


This expression compares each value in the named range "group" against the value in E5 ("A"). Because the criteria is applied to an array with multiple values, the result is an array of TRUE FALSE values like this:


In this array each TRUE corresponds to a value in group A. The IF function evaluates these results and returns the corresponding value from the named range "data". The final result from IF is


Notice only values in group A have survived, and group B values are now FALSE. This array is returned to the MEDIAN function, which automatically ignores FALSE values and returns median value, 3.

Note: when IF is used this way to filter values with an array operation, the formula must be entered with control + shift + enter.

Additional criteria

To apply more than one criteria, you can nest another IF inside the first IF:


To avoid extra nesting, you can also use boolean logic in the criteria.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.