To calculate a median in Excel based on a condition, use the MEDIAN function together with IF in an array formula: =MEDIAN(IF(range=criteria, median_range)). Enter it with Ctrl+Shift+Enter in Excel 2019 and earlier; in Excel 365 or 2021, a regular Enter works because dynamic arrays handle the logic automatically. This returns the middle value of only the cells that meet your condition.
Why MEDIAN with IF Needs an Array Formula
Excel’s MEDIAN function ignores text, logical values, and empty cells when they appear directly in its arguments. However, if you write =MEDIAN(IF(A2:A20="Yes", B2:B20)) as a normal formula, Excel evaluates the IF only for the first cell, giving a wrong result. By entering it as an array formula (Ctrl+Shift+Enter in older versions), Excel evaluates the IF across the entire range, producing an array of values that MEDIAN then processes.
In Excel 365 and Excel 2021, the dynamic array engine handles this automatically, so you can simply press Enter. The formula will spill the result into a single cell because MEDIAN returns one value.
Step-by-Step: How to Build the Formula
- Assume your criteria are in column A (e.g., A2:A20) and the values to average are in column B (B2:B20).
- Pick a cell for the result, say D2.
- Type:
=MEDIAN(IF(A2:A20="Yes", B2:B20)) - If you are using Excel 2019 or earlier, press Ctrl+Shift+Enter (on Mac: Control+Shift+Return). If you are using Excel 365 or 2021, just press Enter.
Example: With sales in B2:B20 and a region in A2:A20, to find the median sales for the “West” region, the formula is =MEDIAN(IF(A2:A20="West", B2:B20)). If the West values are 100, 200, 300, 400, the median is 250.
Using Multiple Criteria (AND Logic)
To apply more than one condition, multiply the IF tests together. For example, to find the median sales where region is “West” and product is “Widget”:
With regions in A2:A20, products in B2:B20, and sales in C2:C20, use:
=MEDIAN(IF((A2:A20="West")*(B2:B20="Widget"), C2:C20))
The multiplication acts as an AND operator: each test returns TRUE/FALSE, which Excel converts to 1/0. Only rows where both are TRUE (1*1=1) are included. Enter with Ctrl+Shift+Enter in older versions, or normally in 365/2021.
Alternatives: MEDIANIFS and Array-Free Approaches
Unlike SUMIFS and AVERAGEIFS, Excel does not have a built-in MEDIANIFS function. However, you can achieve the same result without an array formula by using a helper column:
- In a new column (say D), enter
=IF(A2="West", C2, "")and copy down. - Then use
=MEDIAN(D2:D20). TheIFreturns a blank (empty string) for non-matching rows, andMEDIANignores text, so it only considers numeric values.
This works in all Excel versions and is easier for beginners to understand. Another option is to use the FILTER function (Excel 365/2021) to create a filtered array, then pass it to MEDIAN: =MEDIAN(FILTER(C2:C20, (A2:A20="West")*(B2:B20="Widget"))). This is clean and dynamic.
Common Problems and Troubleshooting
- Getting 0 or wrong result: If you forget Ctrl+Shift+Enter in older Excel, you may get a #VALUE! error or a single-cell result. Re-enter with the key combination.
- Text criteria: Ensure your criteria text matches exactly, including spaces. Use
TRIMorEXACTif needed. - Empty cells:
MEDIANignores empty cells, but if yourIFreturns FALSE (not blank), it will be ignored as well. That’s fine. - Numeric criteria: If your criteria are numbers, do not use quotes. Example:
=MEDIAN(IF(A2:A20=2024, B2:B20)). - Mac vs. Windows: The key combination differs: on Mac, use Control+Shift+Return for array formulas in older versions. In Excel 365/2021, just press Return.
When to Use MEDIAN Instead of AVERAGE
The median is the middle value in a sorted list, which is less affected by extreme outliers than the average. For example, if you have salaries where one executive earns $1,000,000 and everyone else earns $50,000, the median is $50,000 while the average might be $100,000. Use median when you want a typical value that isn’t skewed by a few very high or low numbers. This is common in real estate, income analysis, and performance metrics.
Frequently Asked Questions
Can I use MEDIANIFS in Excel?
No, Excel does not have a MEDIANIFS function. The closest is to use an array formula with MEDIAN and IF, or use the FILTER function in Excel 365/2021.
Why does my MEDIAN IF formula return #VALUE!?
This usually happens when you don’t enter it as an array formula in Excel 2019 or earlier. Select the cell, press F2, then press Ctrl+Shift+Enter. In Excel 365, it should work with a normal Enter.
How do I calculate median with multiple criteria in Google Sheets?
Google Sheets also lacks MEDIANIFS, but you can use the same array formula: =MEDIAN(IF((A2:A20="West")*(B2:B20="Widget"), C2:C20)) and press Ctrl+Shift+Enter (or Cmd+Shift+Enter on Mac).
Does MEDIAN ignore text and empty cells?
Yes, MEDIAN ignores text, logical values, and empty cells when they are directly in the arguments. That’s why the helper column method works: the IF returns an empty string for non-matching rows, which is ignored.
Can I use a cell reference for the criteria?
Yes, instead of typing “West” in the formula, you can use a cell reference like =MEDIAN(IF(A2:A20=E1, B2:B20)) where E1 contains the criteria. This makes it easy to change the condition.
Conclusion
While Excel lacks a dedicated MEDIANIFS function, you can easily compute a conditional median using the array formula =MEDIAN(IF(...)). For complex criteria, multiply conditions inside the IF. If you prefer a non-array approach, use a helper column. Always check your Excel version for the correct entry method, and remember that the median is a robust statistic for skewed data.
Related
- Python String z-score: How to Compute It
- Split CSV File with Bash: 5 Real Methods
- Number 5 Battery Equivalent: What It Is and How to Replace It
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- How to Calculate Quality Percentage in Excel With FormulasTo calculate quality percentage in Excel, divide the number of checks that passed by the total number of…
- Excel FILTER Formula to Find Cells Containing TextTo return rows where a column contains particular text, combine Excel’s FILTER function with SEARCH: with records in…
- INDIRECT in Excel: Create Dynamic Cell ReferencesIn Excel, INDIRECT turns text that looks like a cell or range address into a usable reference. For…
- Excel Workdays Between Dates: Formulas and ExamplesTo count workdays between two dates in Excel, use NETWORKDAYS. With the start date in A2 and the…
- Excel Formula Opposite of CONCATENATE: Split Text ApartThe closest Excel formula to the opposite of CONCATENATE is =TEXTSPLIT(A2,"|"): it takes text in A2 and splits…
- Excel Conditional Formatting IF False: Formula & FixesThe direct answer: Excel’s conditional formatting does not have a built-in “IF false” rule, but you create one…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.