How to Use MEDIAN IF in Excel: Step-by-Step Guide
In this article
Excel has no built-in MEDIANIF function, but you can get the median of values that meet a condition with an array formula. The shortest working version for modern Excel (Microsoft 365, Excel 2021 and later) is =MEDIAN(IF(range=criteria, median_range)), entered normally. In older versions you must press Ctrl+Shift+Enter to make it an array formula. This guide walks through both methods, plus a helper-column workaround that works in every version.
What You'll Need
- Excel 2013 or later (the IF-based array formula works in all these versions; dynamic arrays are only in Microsoft 365 and Excel 2021+).
- A dataset with a text or category column to test and a numeric column to average.
- Basic familiarity with cell references and ranges.
Step-by-Step
- Lay out your data. Put categories in one column (say A2:A100) and numbers in another (B2:B100). Keep the ranges the same size. Blank cells in the number column are ignored by MEDIAN, but text values will cause errors if they end up in the median range.
- Pick an empty cell for the result. For example, D2. Type the formula:
=MEDIAN(IF(A2:A100="North", B2:B100)). Replace "North" with your criteria, or point to a cell likeF2so you can change it without editing the formula. - Enter it correctly for your Excel version. In Microsoft 365 or Excel 2021+, press Enter. In Excel 2019 and earlier, press Ctrl+Shift+Enter. Excel will wrap the formula in curly braces
{ }to show it is an array formula. Do not type the braces yourself. - Check the result. The cell should show the median of only the numbers where column A equals your criteria. If you see
#VALUE!, the ranges are probably different sizes or the median range contains text. - Use a cell reference for flexible criteria. Put "North" in F2 and use
=MEDIAN(IF(A2:A100=F2, B2:B100)). Changing F2 updates the result without rewriting the formula. - Add more conditions if needed. For two criteria, multiply the conditions inside IF:
=MEDIAN(IF((A2:A100="North")*(C2:C100="Active"), B2:B100)). This works in all array-aware versions. In older Excel, remember Ctrl+Shift+Enter. - Copy down for multiple categories. If you have a list of categories in F2:F10, enter the formula in G2 with F2 as the criteria, then copy down. In Microsoft 365 the formula spills automatically if you use a range; otherwise fill handle works.
- Alternative: helper column. If array formulas are not working, add a helper column C with
=IF(A2="North", B2, "")and copy down. Then use=MEDIAN(C2:C100). This works in every Excel version and is easier to audit, though it adds a column.
Common Mistakes
- Forgetting Ctrl+Shift+Enter in older Excel. Without it, the formula returns a single value from the first row that matches, not the median of all matches.
- Mismatched range sizes. If the criteria range is A2:A100 and the median range is B2:B99, Excel returns
#VALUE!. Always use the same number of rows. - Text in the median range. MEDIAN ignores blanks but errors on text. Clean the data or use a helper column that converts text to blank.
- Using MEDIANIF as a function name. It does not exist. Excel will show
#NAME?. Use the IF array method instead. - Criteria with wildcards. MEDIAN(IF(...)) supports wildcards like "North*" only if the criteria is text. For numbers, use direct comparison or cell references.
Tips
- Use
MEDIAN(IF(...))rather thanMEDIANIFSbecause the latter does not exist. For multiple conditions, multiply the boolean arrays as shown above. - If you have Microsoft 365, you can also use
FILTERinside MEDIAN:=MEDIAN(FILTER(B2:B100, A2:A100="North")). This is cleaner and does not need Ctrl+Shift+Enter. - Name your ranges (Formulas > Define Name) to make formulas easier to read and less error-prone.
- Test with a small dataset first. Compare the result to manually sorting the matching values and using MEDIAN on them.
- Remember that MEDIAN ignores blanks but not zeros. If your data has zeros that should be excluded, add a condition like
B2:B100<>0.
Troubleshooting
- Formula returns #VALUE!: Check that all ranges have the same number of rows. Also check for text or error values in the median range. Use
ISNUMBERto test. - Formula returns #N/A: No rows match the criteria. Verify the criteria spelling and that the range includes the data.
- Result looks like an average, not a median: You may have used AVERAGE instead of MEDIAN, or the array formula did not evaluate all rows. In older Excel, re-enter with Ctrl+Shift+Enter.
- Formula works in one cell but not when copied: Check for absolute vs relative references. Use
$A$2:$A$100if you want the range fixed. - Dynamic array spills a #SPILL! error: The formula is trying to spill but there is data in the way. Clear the cells below or use a single-cell result with
@operator if needed.
Frequently Asked Questions
Is there a MEDIANIF function in Excel?
No. Excel does not have a built-in MEDIANIF. You must use an array formula with IF, or a helper column.
Can I use MEDIAN with multiple criteria?
Yes. Multiply the conditions inside the IF function: =MEDIAN(IF((A2:A100="North")*(C2:C100="Active"), B2:B100)). Enter with Ctrl+Shift+Enter in older Excel.
Does MEDIAN(IF(...)) work in Excel 2016?
Yes, but you must press Ctrl+Shift+Enter to make it an array formula. In Excel 2019 and earlier, this is required.
What is the difference between MEDIAN and AVERAGEIF?
AVERAGEIF is a built-in function that averages values meeting a condition. MEDIANIF does not exist, so you use the array formula above to get the median instead of the mean.
Can I use wildcards in the criteria?
Yes, for text criteria. For example, "North*" matches any text starting with North. Wildcards do not work with numeric criteria.
Why does my formula return a single number instead of the median?
In older Excel, you likely forgot Ctrl+Shift+Enter. In Microsoft 365, check that the ranges are correct and that the IF condition is returning an array.