← All how-to recipes

How to calculate a median with a condition (MEDIANIF)

✓ Verified in LibreOffice 25.8.7.3

The median of only the rows matching a criterion — no MEDIANIFS exists, so here's the pattern.

The formula

AppFormulaNotes
Excel=MEDIAN(FILTER(B2:B6,A2:A6="East"))Excel 365/2021. Older Excel: =MEDIAN(IF(A2:A6="East",B2:B6)) entered with Ctrl+Shift+Enter.
Google Sheets=MEDIAN(FILTER(B2:B6,A2:A6="East"))Identical.
LibreOffice Calc=MEDIAN(FILTER(B2:B6,A2:A6="East"))FILTER needs 24.8+; the CSE MEDIAN(IF(...)) form works in older versions.

How it works

AVERAGEIF and SUMIF have -IF versions; MEDIAN never got one in any of the three apps. FILTER fills the gap: it hands MEDIAN just the East values (150, 80, 200), whose middle is 150. Any condition FILTER accepts works — numeric thresholds, dates, multiple ANDed tests. The pre-dynamic-array MEDIAN(IF(...)) array formula does the same everywhere, entered with Ctrl+Shift+Enter in old versions.

Verified, not just documented

We ran =MEDIAN(FILTER(B2:B6,A2:A6="East")) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 150 — exactly the expected result. Every formula here is confirmed by actually executing it.