Average if not equal to 0 and equal to text string in other cell

flagen

New Member
Joined
Jun 22, 2015
Messages
16
Hi all,

I am attempting to create a table of averages based on two criteria. I want to get an average of costs that are not equal to 0 and fit into a certain category. I have tried both averageifs and sumifs/countifs functions. Here are the two formulas I have most recently tried. It says there is an error in my formula in both of them.

Code:
=AVERAGEIFS(O$3:O2196,LEFT($C$3:$C2196,10),$K2206,O$3:O2196,"<>0")

=SUMIFS(O$3:O2196,LEFT($C$3:$C2196,10),$K2206,O$3:O2196,"<>0"))/COUNTIFS(LEFT($C$3:$C2196,10),$K2206,O$3:O2196,"<>0"))

I am averaging everything in column "O" that doesn't equal 0 and fits within one of the categories in column "C" based on the text string given in column "K". This is a column of averages I placed at the bottom of my data. Any help is appreciated, thank you!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
There's probably a shorter way but till someone comes along with it try...

=SUMPRODUCT((LEFT($C$3:$C$2196,10)=$K2206)*($O$3:$O2196<>0)*($O$3:$O2196))/SUMPRODUCT(--(LEFT($C$3:$C$2196,10)=$K2206)*($O$3:$O2196<>0))
 
Upvote 0
That worked! Can you explain what that does to get to the answer though? I would never have thought of SUMPRODUCT for this.

Thank you Special-K.
 
Upvote 0
Additionally, if I wanted to do the same thing, would it be possible to change the first criteria to LEFT and RIGHT string filters? As in, check the left # of characters and right # of characters against "K2206". Example using my old equation:

=AVERAGEIFS(O$3:O2196,AND(LEFT($C$3:$C2196,5),RIGHT($C$3:$C2196,3)),$K2206,O$3:O2196,"<>0")
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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