If you want to cal­cu­late a medi­an val­ue with a con­di­tion, you can­not use a sim­ple MEDIAN func­tion because it needs only num­bers. We have to use anoth­er func­tion that will reduce the num­ber of wages we look at. 

Medi­an with condition

Typ­i­cal­ly, when we want to add a con­di­tion to anoth­er func­tion we can use the IF func­tion and make a log­i­cal test. In our case, the log­i­cal test will be sim­ple. We just have to check each cell in the Depart­ment col­umn whether it’s equal to the name of the Depart­ment we look at now. Since we are com­par­ing a sin­gle cell to a whole range, Excel will check every sin­gle cell in a giv­en range (Fig. 1). 

Comparing a single cell to a range of cells
Fig. 1 Com­par­ing a sin­gle cell to a range of cells

If a cell in the range is equal to the tar­get cell, we want the func­tion to return prop­er wages, i.e. the wages from the same row. If the log­i­cal test result is FALSE, we want to have some­thing that the MEDIAN func­tion will ignore which, in most cas­es, is an emp­ty text string. How­ev­er, I want to show you that the IF func­tion real­ly returns some­thing so let’s write “no” (Fig. 2).

=IF($B$2:$B$13=E2,$C$2:$C$13,“no”)

IF function
Fig. 2 IF function

We can see that Dynam­ic Array Excel spilled the results and we have wages only for the depart­ments we chose. For oth­er depart­ments we have ‘no’. Now, we can put this func­tion into the MEDIAN func­tion (Fig. 3).

=MEDIAN(IF($B$2:$B$13=E2,$C$2:$C$13,“no”))

MEDIAN function with IF function
Fig. 3 MEDIAN func­tion with IF function

Now, we’ve cal­cu­lat­ed the medi­an val­ue with a con­di­tion for each depart­ment. We can see that for HR it’s $4,000, for IT it’s $8,100 and for Mar­ket­ing it’s $5,900. Those are the mid­dle val­ues for each depart­ment (Fig. 4). 

Median values for each department
Fig. 4 Medi­an val­ues for each department

https://www.youtube.com/watch?v=DUYBBhR3wz4