MEDIAN with multiple IF conditions

Ken Soona

New Member
Joined
Feb 19, 2014
Messages
29
I need to write a formula that calculates a median value, with several IF clauses. EG 'data' tab is below:

PersonSalesMargin
Tommy2100
Jimmy3300
Henry5500
Jimmy4200
Jimmy6100
Tommy10200
Henry3700
Henry51000
Tommy7500

<tbody>
</tbody>

In another tab, I have what I want the result to be, as well as some constraints
MinSalesMinMargin
00
Namep50Salesp50Margin
Tommy(7)(200)
Jimmy(4)(200)
Henry(5)(700)

<tbody>
</tbody>

I need to write a formula that will calculate median for each person named, with or without constraints on MinSales and MinMargin.

I have something like this so far in cell B5. This should calculate to 7, the median number for sales for Tommy, given a sale minimum of 0 or greater, and a margin minimum of 0 or greater.

{=MEDIAN(IF(AND(data!$A$2:$A$10=A5,data!$B$2:$B$10>=B2,data!!$C$2:$C$10>=C2),data!$A$2:$A$10))}

I have also tried:

{=MEDIAN(IF(data!$A$2:$A$10=A5,IF(data!$B$2:$B$10>=B2,IF(data!!$C$2:$C$10>=C2,data!$A$2:$A$10))))}

In another note...I have gotten something like this to work elsewhere, with two IF instead of three, and both of them are static numbers, rather than dynamic references. That is unhelpful though, I need to make this such that someone else can plug numbers into the min sales and min margin cells to see how the data differ.

Any help is appreciated, thank you!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
The use of function AND is the problem: it's delivering a single TRUE or FALSE. What you need to do is multiply the arrays. Note your sample formula has an extraneous exclamation mark next the the spreadsheet name 'data.'

Put this array formula into B5 with Ctrl+Shift+Enter and then copy across and down.

Code:
=MEDIAN(IF((data!$A$2:$A$10=$A5)*(data!$B$2:$B$10>=$B$2)*(data!$C$2:$C$10>=$C$2),data!B$2:B$10))
 
Upvote 0
I know the AND part, I was just trying to state that I had tried more than one thing, even if it was wrong ;)

Your solution works perfect, thank you!
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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