Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Median If Multiple Criteria: How-To Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Excel has no built-in MEDIANIFS function, so to get a median based on more than one condition you combine MEDIAN with IF in an array formula, or use MEDIAN with FILTER in Microsoft 365. The array version works in every Excel version: =MEDIAN(IF((range1=criteria1)*(range2=criteria2),median_range)), entered with Ctrl+Shift+Enter in older versions. The FILTER version is shorter and easier to read: =MEDIAN(FILTER(median_range,(range1=criteria1)*(range2=criteria2))). Both return the middle value of only the rows that match every condition.

What You'll Need

  • Excel 2010 or later for the array formula; Microsoft 365 or Excel 2021 for the FILTER version.
  • A data table with one header row, no blank rows inside the data, and consistent column types (text in text columns, numbers in number columns).
  • Criteria values stored in their own cells so you can change them without editing the formula.
  • For older Excel versions: the keyboard shortcut Ctrl+Shift+Enter (Windows) or Command+Shift+Enter (Mac) to commit an array formula.

Step-by-Step

  1. Lay out your data cleanly. Put headers in row 1 and data starting in row 2. For example: A1 = Region, B1 = Product, C1 = Sales. Data runs from row 2 to row 200. Blank cells inside the range will be treated as zero by the array formula, so fill or remove them first.
  2. Create a small criteria area. In cells E1 and E2 type the labels Region and Product. In F1 type the region you want (for example North) and in F2 the product (for example Widget). Referencing cells keeps the formula editable.
  3. Write the array formula. In an empty cell enter:
    =MEDIAN(IF((A2:A200=F1)*(B2:B200=F2),C2:C200))
    The multiplication acts as AND: a row must match both criteria to be included. The IF returns the C values for matching rows and FALSE for the rest, and MEDIAN ignores FALSE.
  4. Commit it correctly. In Excel 2010 through 2019, press Ctrl+Shift+Enter, not Enter. Excel wraps the formula in curly braces { } automatically. Do not type the braces yourself. In Microsoft 365 and Excel 2021 the formula calculates with a normal Enter because dynamic arrays handle it.
  5. Use FILTER instead if you have Microsoft 365 or Excel 2021. Enter:
    =MEDIAN(FILTER(C2:C200,(A2:A200=F1)*(B2:B200=F2)))
    This is a normal formula, no special keystroke needed, and it is easier to audit. If no row matches, FILTER returns a #CALC! error; wrap it in IFERROR to show a blank or a message.
  6. Add a third criterion the same way. Multiply another condition into the array: =MEDIAN(IF((A2:A200=F1)*(B2:B200=F2)*(D2:D200>=F3),C2:C200)). Each additional condition is one more bracketed comparison joined by an asterisk.
  7. Check the result against a manual filter. Select your data, turn on Data > Filter, filter the two columns to the same values, and select the visible numbers in the median column. The status bar shows Average and Count by default; right-click the status bar and enable Median to see the value. It should match your formula.
  8. Copy the formula down or across. If you want medians for several region/product pairs, put each pair in its own row and copy the formula down. Use absolute references ($A$2:$A$200) for the data ranges so they do not shift.

Common Mistakes

  • Pressing Enter instead of Ctrl+Shift+Enter in older Excel. The formula returns a wrong number or #VALUE! because it is evaluated as a single cell rather than an array. Re-enter it with the correct shortcut.
  • Typing the curly braces manually. Excel treats {=MEDIAN(...)} typed by hand as text. Let Excel add the braces by committing with Ctrl+Shift+Enter.
  • Using AND inside the array. AND(A2:A200=F1,B2:B200=F2) collapses to a single TRUE/FALSE for the whole range, not row by row. Use multiplication of the comparisons instead.
  • Mismatched range sizes. If the criteria ranges are 199 rows and the median range is 200 rows, the formula returns #N/A or a wrong result. All ranges must be the same height.
  • Text that looks like numbers. Numbers stored as text are ignored by MEDIAN, so the result can be too low or an error. Convert them with Data > Text to Columns or VALUE().
  • Blank cells inside the median range. In the array version, blanks become zero and pull the median down. Clear or fill them, or restrict the range to the actual data.
  • Criteria with wildcards or case differences. The equals comparison is not case-sensitive, but wildcards like * and ? do not work with = in this construction. Use SEARCH or ISNUMBER for partial matches.

Tips

  • Keep criteria in cells rather than hard-coded text so the formula is reusable and easy to audit.
  • Use named ranges (Formulas > Define Name) for the data columns to make the formula readable: =MEDIAN(IF((Region=F1)*(Product=F2),Sales)).
  • Wrap the whole formula in IFERROR to handle the no-match case gracefully: =IFERROR(MEDIAN(FILTER(...)),"No matches").
  • For a quick sanity check, use a PivotTable with the values field set to Median; it is not a formula but it confirms the number.
  • If you need the median for many combinations, build a small lookup table and copy the formula down rather than editing it repeatedly.
  • Remember that MEDIAN of an even count returns the average of the two middle values, so results can be decimals even when the source data is whole numbers.

Troubleshooting

  • #VALUE! error: the formula was not entered as an array in an older Excel version, or a range contains text where numbers are expected. Re-enter with Ctrl+Shift+Enter and check the median column for text.
  • #N/A error: range sizes do not match. Select each range in the formula bar and confirm they are the same number of rows.
  • #CALC! error (FILTER version): no rows match the criteria. Check spelling and trailing spaces in the criteria cells, and confirm the criteria values exist in the data.
  • Result looks too low: blank cells in the median range are being counted as zero. Clear them or tighten the range.
  • Result looks too high: numbers stored as text are being skipped, or a criterion is matching more rows than intended. Use COUNTIFS with the same criteria to see how many rows match, then compare with the median calculation.
  • Formula returns a single value instead of a median: the IF is collapsing the array. Confirm you used multiplication, not AND, and that the formula is committed as an array where required.

Frequently Asked Questions

Is there a MEDIANIFS function in Excel?

No. Excel has SUMIFS, COUNTIFS and AVERAGEIFS, but no MEDIANIFS. You must use MEDIAN with IF as an array formula, or MEDIAN with FILTER in Microsoft 365 and Excel 2021.

Do I need Ctrl+Shift+Enter in Microsoft 365?

No. Microsoft 365 and Excel 2021 use dynamic arrays, so a normal Enter works for both the IF and FILTER versions. Older versions require Ctrl+Shift+Enter for the IF version.

Can I use more than two criteria?

Yes. Add another bracketed comparison joined by an asterisk for each condition. All ranges must be the same height as the median range.

Why does my formula return zero?

Most often the median range contains blanks, which the array formula treats as zero, or the criteria do not match any rows. Check the match count with COUNTIFS first.

Can I use wildcards in the criteria?

Not with the equals comparison in this construction. For partial text matches, use ISNUMBER(SEARCH("text",range)) as the condition instead.

Does the median ignore text and blanks?

MEDIAN ignores text and logical values in a normal range, but inside the IF array, non-matching rows become FALSE and are ignored, while blanks in the median range become zero. Clean the range to avoid skew.