AVG, MED, 75th of filtered list, No Zeros

Excel1991

Board Regular
Joined
Aug 1, 2018
Messages
58
I am attempting to find the average, median and 75th percentile in a list of data that I have, but I would like to exclude zeros from the calculations. Column D has various years (2012,2013,2014) and Column E has salaries. Essentially, I am trying to develop formulas that do these three things:



  1. "If the year is 2012, find the average of the salaries, but do not include zeros"
  2. "If the year is 2012, find the median of the salaries, but do not include zeros"
  3. "If the year is 2012, find the 75th percentile of the salaries, but do not include zeros"

Are there criteria formulas that can accomplish this? or are there formulas I could run if I first filter the data by year?
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Good Morning,

My example data has year from A1:A13 and values including zeros from B1:B13. Using the data table, I have developed the following formulas to solve your problems

1. = AVERAGEIFS(B1:B13,B1:B13,"<>"&0,A1:A13,"="&2012)
2. =PERCENTILE.EXC(IF((B1:B13>0)*(A1:A13=2012),B1:B13,""),0.75): Enter as an array formula by entering Shift + Control + Enter
3. =MEDIAN(IF((B1:B13>0)*(A1:A13=2012),B1:B13,"")): Enter as an array formula by entering Shift + Control + Enter

Kind regards

Saba
 
Upvote 0
Try
Excel Workbook
DEFGH
1YearsSalariesYear2014
2201257144Average105,520.67
3201279455Median92,222.00
4201212168775% Percentile144,092.00
520120
62012138579
72012148044
820120
92012133895
10201269187
11201353775
1220130
1320130
14201372360
152013101314
162013121048
172014195962
18201428378
19201492222
Sheet
 
Upvote 0
Try
DEFGH
Average
Median
75% Percentile

<colgroup><col style="width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:39px;"><col style="width:117px;"><col style="width:91px;"></colgroup><tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]1[/TD]
[TD="bgcolor: #c0c0c0"]Years[/TD]
[TD="bgcolor: #c0c0c0"]Salaries[/TD]

[TD="bgcolor: #c0c0c0"]Year[/TD]
[TD="align: right"]2014[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]2[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]57144[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffff00]#ffff00[/URL] , align: right"] 105,520.67 [/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]3[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]79455[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffff00]#ffff00[/URL] , align: right"] 92,222.00 [/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]4[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]121687[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffff00]#ffff00[/URL] , align: right"] 144,092.00 [/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]5[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]0[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]6[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]138579[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]7[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]148044[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]8[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]0[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]9[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]133895[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]10[/TD]
[TD="align: right"]2012[/TD]
[TD="align: right"]69187[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]11[/TD]
[TD="align: right"]2013[/TD]
[TD="align: right"]53775[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]12[/TD]
[TD="align: right"]2013[/TD]
[TD="align: right"]0[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]13[/TD]
[TD="align: right"]2013[/TD]
[TD="align: right"]0[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]14[/TD]
[TD="align: right"]2013[/TD]
[TD="align: right"]72360[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]15[/TD]
[TD="align: right"]2013[/TD]
[TD="align: right"]101314[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]16[/TD]
[TD="align: right"]2013[/TD]
[TD="align: right"]121048[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]17[/TD]
[TD="align: right"]2014[/TD]
[TD="align: right"]195962[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]18[/TD]
[TD="align: right"]2014[/TD]
[TD="align: right"]28378[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]19[/TD]
[TD="align: right"]2014[/TD]
[TD="align: right"]92222[/TD]

</tbody>

Spreadsheet Formulas
CellFormula
H2=AVERAGEIFS($E$2:$E$19,$D$2:$D$19,$H$1,$E$2:$E$19,"<>0")
H3{=MEDIAN(IF($D$2:$D$19=$H$1,IF($E$2:$E$19<>0,$E$2:$E$19)))}
H4{=PERCENTILE(IF($D$2:$D$19=$H$1,IF($E$2:$E$19<>0,$E$2:$E$19)),0.75)}

<tbody>
</tbody>
Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4




Worked like a charm, much appreciated. You saved me lots of time
 
Upvote 0
I am about 99% that these formulas are working as they should be. In an attempt to check I have taken the data, filtered it by year 2012. Copy and pasted these 2012 values, sorted then by Largest to smallest, deleted the zeros and then took an average to make sure I was getting the same numbers. The numbers for the sample checked out.

I was curious if there are any other ways to perform a "sanity check" on these formulas to ensure they are working accurately.
 
Upvote 0
Checking a year manually like you did is probably the best check. If it returns the correct answer for the year 2012, it should work for the other years. Since the 50th percentile should equal the median you could run a check to make sure both formulas (using the 50th percentile) return the same answer.
 
Upvote 0
Thank you for the response. The formulas appear to beworking well to me. The 50% percentile check also works when assessing themedian so that’s good.


I have another question though. I have 4 columns thatcontain data and then a 5th column that sums the others up (so E5 isthe sum of (a5, b5, c5, d5) and e6 would be sum of (a6,b6,c6,d6) and soon.At the bottom of my spreadsheet iswhere I used your formulas to search through the columns without counting thezeros.


So at the bottom I have the separate formulas performing thefollowing



  • avg of column A,
  • avg of B,
  • avg of C,
  • Avg of D,
  • avg of the total column.


I’m trying to wrap myhead around why the sum of these formulas (Average of a,b,c,d) wouldn’t equalthe Average of the total column. In my head I’m curious why the average of mytotal column wouldn’t equal this:


Average of columnA,


+Average of B,


+Average of C,


+Average ofD,


Average of the total column.


Essentially the sum of theaverage for each column does not equal the same as taking the average of thetotal column. Why would this be?
 
Upvote 0
If you had included the 0 values Sum(Average( column A-D)) would equal the average of the total column.
See the small example below.
If you take the actual average of columns B - D and add them they equal the average of the total column. See row 9

However if you take the average of the columns excluding the 0 values it doesn't. See row 12. Column B & D are the average of only 4 values and column C is the average on only 3 values.
Excel Workbook
ABCDE
1Total
21023
325411
43003
506814
647516
7Sum10181947
8
9Average23.63.8
10Sum of averages9.49.4
11
12Average excluding 02.564.75
13Sum of averages13.25
Sheet
 
Upvote 0
Im very impressed that you understood exactly what I was talking about just through that paragraph. This is exactly what happened for me. So it makes sense that your row 13 equal E10 correct? Since the total row has no zeros, its denominator would be higher. so B12+C12+D12 would not equal E12 (which would be the same as the 9.4 since there are zeros). It seems like its making sense to me now. I appreciate the visual.

On another note, how did you incorporate the small spreadsheet? May help me in future post to give a clearer picture in what im trying to accomplish. I apologize if this is already addressed somewhere.
 
Last edited:
Upvote 0
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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