I need to return a median of only a certain category on a spread sheet. Example Below
Airline 5
Auto 20
Auto 3
Bike 12
Airline 12
Airline 39
ect.
How can I write a formula to only return a median value of the Airline Categories. Similar to Average if, only for median. I cannot re-arrange the values. Thank you!
When you are finding median manually, you need to sort the data in an ascending order but in Excel, you can simply use the Median function and select the range and you will find your median. We take the same example as above to find the median of marks obtained by students. So we use =MEDIAN(B2:B12).
To calculate a conditional median based on one or more criteria you can use an array formula that uses the MEDIAN and IF functions together. In the example shown, the formula in F5 is: =MEDIAN(IF(group=E5,data)) where "group" is the named range B5:B14, and "data" is the named range C5:C14.
Assuming your categories are in cells A1:A6 and the corresponding values are in B1:B6, you might try typing the formula =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,""))
in another cell and then pressing CTRL+SHIFT+ENTER
.
Using CTRL+SHIFT+ENTER
tells Excel to treat the formula as an "array formula". In this example, that means that the IF
statement returns an array of 6 values (one of each of the cells in the range $A$1:$A$6
) instead of a single value. The MEDIAN
function then returns the median of these values. See http://www.cpearson.com/excel/arrayformulas.aspx for a similar example using AVERAGE
instead of MEDIAN
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With