Explanation
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.
The IF function evaluates these results and returns the corresponding value from the named range “data”.
For example, =MEDIAN(1,2,3,4,5) returns 3.