median...if

Duritz

Board Regular
Joined
Apr 28, 2005
Messages
226
Hi. Like the function "sumif", I need a "medianif" funtion, ie, find the median of a set in column B given that their corresponding figure in A matches a variable.

So, for example:

A B
5 1.2
2 1.4
3 1.4
7 1.2
5 2.3
4 1.6
3 1.5
5 2.2
6 1.1
7 1.9
5 0.9
4 1.9
5 1.7

And if the variable to match is 5, then the figures to find the median of are 1.2, 2.3, 2.2, 0.9 and 1.7, of which of course the median is 1.7.

Any ideas?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,439
Office Version
  1. 365
Platform
  1. Windows
Duritz

Try this:
E2: =MEDIAN(IF(A1:A13=E1,B1:B13))
Confirmed with Ctrl+Shift+Enter not just Enter
Mr Excel.xls
ABCDEF
151.2Variable:5
221.4Result:1.7
331.4
471.2
552.3
641.6
731.5
852.2
961.1
1071.9
1150.9
1241.9
1351.7
14
Median If
 

Barry Katcher

Well-known Member
Joined
Feb 25, 2002
Messages
4,053
Try this combo:

Formula in B16 is: =SUMIF(A1:A13,A16,B1:B13)/COUNTIF(A1:A13,A16)
Book1
ABCD
151.2
221.4
331.4
471.2
552.3
641.6
731.5
852.2
961.1
1071.9
1150.9
1241.9
1351.7
14
15
1651.66
Sheet2


P.S. If my formula is too cumbersome, then use Peter's - it offers array of hope. :)
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
Barry - the OP wanted the median, not the mean

Gene, "The Mortgage Man", Klein
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,439
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

P.S. If my formula is too cumbersome, then use Peter's - it offers array of hope. :)
:LOL: :ROFLMAO:
 

Barry Katcher

Well-known Member
Joined
Feb 25, 2002
Messages
4,053
Ooops! I didn't realize there was a difference between median and mean. I suppose mean equates to average. What is the definition of median?
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015

ADVERTISEMENT

mean=average
median = the middle number in a sorted vector. If there are two middle numbers - i.e. if there are a odd number of numbers in the vector - then the median is the average of the two middle numbers.

Gene, "The Mortgage Man", Klein
 

Barry Katcher

Well-known Member
Joined
Feb 25, 2002
Messages
4,053
Thanks, Gene.

Your next YouTube video should be about all those putz's that don't know the difference between "mean" and "median" :)

P.S. Shouldn't that be:

"If there are two middle numbers - i.e. if there are an even number of numbers in the vector - then the median is the average of the two middle numbers."
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
Barry - yes of course you are right. It is even. Maybe my next youtube video should be about senile math majors who can't remember the difference between odd and even!

Gene, "The Mortgage Man", Klein
 

Forum statistics

Threads
1,136,649
Messages
5,676,991
Members
419,667
Latest member
MegEri

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
Top