Count only if

rinnue

Board Regular
Joined
Feb 28, 2003
Messages
142
A________________B
Manager__________3
Laborer___________3
Manager _________N/A
Foreman__________2

I want to find the average of the Manager numbers. I am using Sumif to add the numbers in column B corresponding to Manager in column A, but what do I use to find the number to divide by? I need to count the number of occurances of "Manager", but only if they have corresponding numbers. Hope this makes sense. If only Countif workeed like Sumif......
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What answer do you expect from your example?

If there are #N/As in the range as shown then perhaps

=AVERAGE(IF(ISNUMBER(B1:B4),IF(A1:A4="Manager",B1:B4)))

confirmed with CTRL+SHIFT+ENTER

or if you want to count the #N/A as a zero (to give a result of 1.5 rather than 3)

=AVERAGE(IF(A1:A4="Manager",IF(ISNUMBER(B1:B4),B1:B4,0)))

also confirmed with CTRL+SHIFT+ENTER
 
Upvote 0
I would expect it to be 3 since there is no data, or N/A, in one of the manager fields. Didn't know there was an Average function. I will play with that and see what I can get. Thanks.
 
Upvote 0
Not sure why but I get a 0 when I use either formula. I set my data in columns A and B exactly like I posted.

Now some of my columns of data I want to use this in are not adjacent to each other. Not sure if that will matter in the future.

Is there no function for counting that has syntax like SumIf?
 
Upvote 0
Well, you can use COUNTIF....

one of the ways to do what you ask, usually is

=SUMIF(A1:A4,"Manager",B1:B4)/COUNTIF(A1:A4,"Manager")

but this won't work if you have errors in your ranges.

What formula did you try?

note: it shouldn't matter whether the columns are adjacent or not
 
Upvote 0
For the CountIf formula, that is exactly what I tried and the problem was that any errors(N/A) in the data were processed like zeros, however i need the bad data ignored.

I tried both of the formulas you posted and both = 0.

I appreciate your help and I apologize for making this difficult. I am by no means an Excel wiz though.
 
Upvote 0
You have to confirm the formula with CTRL+SHIFT+ENTER so that curly braces appear around the formula in the formula bar.

To do this.....

Select cell with formula
Press F2
Hold down CTRL and SHIFT keys at the same time and whilst doing so...
...press ENTER

should look like this
workday.xls
ABCDE
1Manager3
2Laborer33
3Manager#N/A
4Foreman2
5
Sheet4


Formula in D2

=AVERAGE(IF(ISNUMBER(B1:B4),IF(A1:A4="Manager",B1:B4)))
 
Upvote 0
Seems to be working great!!!!

So why is the confirming step needed? Other formulas I have work fine. Is this a special formula?

Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,956
Members
448,535
Latest member
alrossman

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