TRIMMEAN is no AVERAGEIF unless you know how
I stumbled upon an interesting question the other day, which was; ‘how do I find the average of a range of numbers that meet criteria, and by the way, I want to exclude the outliers?’
Now, if all we needed was a simple average that met criteria we could use an AVERAGEIF or AVERAGEIFS formula.
Or if we just wanted to exclude the outliers we could use the TRIMMEAN function which returns the mean (average) of the interior proportion of values.
The syntax is:
TRIMMEAN(array, percent)
Where the array is the range containing your values and percent is the fractional number of data points you want to exclude from the top and bottom of your data set.
But we want to effectively find the AVERAGEIF and TRIMMEAN.
Unfortunately this pair don’t get on so well in the same cell so I’ve got an alternative and it’s not called TRIMMEANIF….but maybe there’s an idea.
Note to self; write to Microsoft suggesting new TRIMMEANIF function!
Ok, let’s take this list as our example:

And let’s say we want to find the average Units for Size 8 and exclude the top and bottom 40%.
Note: you wouldn’t normally exclude 40% of your sample but since mine is so small (so it’ll easily fit on the screen) I have had to make the proportion to exclude quite large.
Here’s the formula:
=TRIMMEAN(IF(B2:B12=8,C2:C12),40%)
It’s an array formula so you need to enter it with CTRL+SHIFT+ENTER.
In English it reads: Find the MEAN (average) of the values in the range C2:C12, where the size in the range B2:B12 is 8, oh, and by the way, ignore the top and bottom 40% of the values.
My nested IF formula returns an array of Units that are size 8, and if we step through how the formula evaluates we can see it looks like this:
Step 1:
Evaluate the IF formula logical test and expand the range C2:C12:
=TRIMMEAN(IF({TRUE;TRUE;TRUE;TRUE;TRUE;FALSE;FALSE; FALSE;FALSE;FALSE;FALSE}, {2;4;5;6;9;4;10;8;9;4;1}), 40%)
Step 2:
Create an array of the values that evaluate to TRUE:
=TRIMMEAN({2;4;5;6;9}, 40%)
Step 3:
Strip out the outliers from the array of values:
=TRIMMEAN({4;5;6})
Step 4:
Find the mean (average) of the remaining values:
=5
Note: if you run this formula through the Evaluate Formula tool you will see it work through the steps above.
Spread the Word
If you liked this or know someone who could use it please click the buttons below to share it with your friends on LinkedIn, Google+1, Facebook and Twitter.
And if you want to help start a movement to get Microsoft to include a new TRIMMEANIF function in the next release of Excel click on all of them! Heck, why not click on all of them anyway and have a clickety click day :-)
Have a great day,
Mynda
Co-founder & Head Excel Geek
My Online Training Hub
|