# median...if

#### Duritz

##### Board Regular
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
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
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
Barry - the OP wanted the median, not the mean

Gene, "The Mortgage Man", Klein

#### Peter_SSs

##### MrExcel MVP, Moderator

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

#### Barry Katcher

##### Well-known Member
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

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
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
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

Replies
11
Views
188
Replies
1
Views
292
Replies
3
Views
201
Replies
4
Views
97
Replies
5
Views
302

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.

### Which adblocker are you using?

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

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