Median If?

John McGraw

Board Regular
Joined
Feb 25, 2002
Messages
76
Is there any trick I can pull to get the
median for a series of data among only the data chosen by a condition?

Lets say column A has lables indicating the age of people, and column B has their height. Can I somehow write a formula to get the median height for people who's age is 20 for example?

I figured a way to do this for the average. (SUMIF(A:A,"=20",B:B)/COUNTIF(A:A,"=20))

But the other functions like median, min, max, etc have me stumped.

Thanks for any help.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
On 2002-02-26 23:58, John McGraw wrote:
Is there any trick I can pull to get the
median for a series of data among only the data chosen by a condition?

Lets say column A has lables indicating the age of people, and column B has their height. Can I somehow write a formula to get the median height for people who's age is 20 for example?

I figured a way to do this for the average. (SUMIF(A:A,"=20",B:B)/COUNTIF(A:A,"=20))

But the other functions like median, min, max, etc have me stumped.

Thanks for any help.

Hi John,

Array-enter

=MEDIAN(IF(A2:A10=20,B2:B10))

where A2:A10 houses the ages and B2:B10 corresponding heights.

You need to hit control+shift+enter at the same time, not just enter, to array-enter a formula.

Conditional MIN and conditional MAX follow the same logic.

By the way, when you use the equality test, your conditional average can be simplified a bit:

=SUMIF(A:A,20,B:B)/MAX(1,COUNTIF(A:A,20))

I added the MAX bit to prevent #DIV/0! in case the condition ("=20") does not hold.

Aladin

Addendum: John, you can also put a condition in a cell of its own and use that cell in the formulas like in

=SUMIF(A:A,E1,B:B)/MAX(1,COUNTIF(A:A,E1))

=SUMIF(A:A,"<"&E1,B:B)/MAX(1,COUNTIF(A:A,"<"&E1))

etc.
This message was edited by Aladin Akyurek on 2002-02-27 00:31
This message was edited by Aladin Akyurek on 2002-02-27 03:05
 
Upvote 0
Aladin,

You are amazing! I dont know how you are always able to answer so many questions so precisely!

Thanks,

John
 
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top