Median formula with multiple imbedded IF functions

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
888
Office Version
  1. 365
Platform
  1. Windows
I am looking to find the Median of a data set but I only want the formula to consider certain cells.

The Median number I want found is in the column called [DTQ]
The only DTQ numbers I want it to consider are ones that are not labeled as Exclude in the [Customer Exlusions] Column, and have a Date Quoted between the two dates listed in E1 and F1

I wrote the below formula but I get a #NUM! error....

={ROUND(MEDIAN(IF(WO[Customer Exclusions]<>"Exclude",IF(WO[Date Quoted],">="&$F$1,IF(WO[Date Quoted],"<="&$E$1,WO[DTQ])))),0)}

Any help would be appreciated!

Thank you

Example.xlsx
ABCDEF
1Date QuotedDTQCustomer Exclusions2020-08-012020-08-20
22020-08-203
3
42020-08-204
52020-08-204
6ExcludeMedian:#NUM!
75
82020-08-182
92020-08-182
102020-08-187
112020-08-132
122020-08-176
132020-08-187
142020-08-198Exclude
152020-08-132
162020-08-2010
17Exclude
182020-08-189
19Exclude
202020-08-1711
212020-08-115
222020-08-1814Exclude
232020-07-135
242020-07-102
252020-07-146Exclude
262020-07-146
272020-07-135
282020-07-102
292020-06-112
302020-06-178Exclude
312020-06-112
Sheet1
Cell Formulas
RangeFormula
F6F6=ROUND(MEDIAN(IF(WO[Customer Exclusions]<>"Exclude",IF(WO[Date Quoted],">="&$F$1,IF(WO[Date Quoted],"<="&$E$1,WO[DTQ])))),0)
F7F7=ROUND(MEDIAN(B2:B5,B8:B13,B15:B16,B18,B20:B21),0)
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
WOR=Sheet1!$C$9F6


Note: This is just an example, the original data set has over 22000 rows
Carla
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try changing ">="&$F$1 to >=$F$1 the double quote method is only used in countifs, sumifs, etc. Functions that don't have IFS in the name need to be done without.

edit:-

I just noticed that you have a couple of extra commas as well and your < and > should be the opposite way around once the formula is corrected, this should be right once it's array entered.

=ROUND(MEDIAN(IF(WO[Customer Exclusions]<>"Exclude",IF(WO[Date Quoted]<=$F$1,IF(WO[Date Quoted]>=$E$1,WO[DTQ])))),0)
 
Upvote 0
I get the following error:

1597958500405.png
 
Upvote 0
Try this

Book1
ABCDEF
1Date QuotedDTQCustomer Exclusions4404444063
2440633
3
4440634
5440634
6ExcludeMedian:5
75
8440612
9440612
10440617
11440562
12440606
13440617
14440628Exclude
15440562
164406310
17Exclude
18440619
19Exclude
204406011
21440545
Sheet1
Cell Formulas
RangeFormula
F6F6=ROUND(MEDIAN(IF((B2:B21)-IF(C2:C21="Exclude",B2:B21)>0,(B2:B21)-IF(C2:C21="Exclude",B2:B21),FALSE)),0)
F7F7=ROUND(MEDIAN(B2:B5,B8:B13,B15:B16,B18,B20:B21),0)
 
Upvote 0
Unfortunately I cannot set a range (B2:B21) - can this be a table reference instead? - WO[DTQ]

The original data is over 22000 rows long and can vary
 
Upvote 0
Sorry there is an issue with the above, If you have 0 in DTQ then it will ignore it
 
Upvote 0
I get the following error:
Was that before or after I edited my earlier reply?

I noticed that some additional changes were needed after posting so went back and added the formula to it with the changes already made.
 
Upvote 0
Was that before or after I edited my earlier reply?

I noticed that some additional changes were needed after posting so went back and added the formula to it with the changes already made.

I didnt notice your update! Hurray it works!!!

Thank you so much!
 
Upvote 0
Yes you can consider whole table column Instead of cell reference
and Try This

Book1
ABCDEF
1Date QuotedDTQCustomer Exclusions01/08/202020/08/2020
220/08/202035
3
420/08/20204
520/08/20204
6Exclude
7
818/08/20202
918/08/20202
1018/08/20207
1113/08/20202
1217/08/20206
1318/08/20207
1419/08/20208Exclude
1513/08/20202
1620/08/202010
17Exclude
1818/08/20209
19Exclude
2017/08/202011
2111/08/20205
Sheet1
Cell Formulas
RangeFormula
E2E2=ROUND(MEDIAN(IF((A2:A21>=E1)*(A2:A21<=F1)*(C2:C21<>"Exclude"),B2:B21)),0)
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

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