COUNTIFS with AND or nested COUNTIFS?

somanyqs

Board Regular
Joined
Oct 2, 2007
Messages
76
My brain is jamming a bit to start the day.
I'm trying to make a formula that given one cell, checks if that , counts how many times other cells in that row are >1.

So for example,
A1 = Bob [or whatever name you want to enter]
A2 = Counts how many different ingredients were purchased by person in A1 for their salad

Col C: People (list of people and their salad purchases (all unique))
Col D: Number of croutons purchased
Col E: Number of bell peppers purchased
Col F: Number of tomatoes purchased

So I would like to enter Bob or Anne or Joe in cell A1, and then cell A2 will spit out how many different ingredients the person in A1 purchased. So if they purchase 20 croutons, no bell peppers and 2 tomatoes, cell A2 will show "2" since they purchased croutons and tomatoes.

So I know I can do this in a not-so-elegant way (since C is unique):
A2 = COUNTIFS(C:C,"="&A1,D:D,">0") + COUNTIFS(C:C,"="&A1,E:E,">0") + COUNTIFS(C:C,"="&A1,F:F,">0")

But I'm wondering if I can somehow use an AND or COUNTIFS or something else to combine this all into one formula. More like (though I know this doesn't work)
A2 = COUNTIFS(C:C,"="&A1,COUNTIFS(D:F,">0"))

Which would be a great help since in reality I have a ton more ingredients to count (say like 50 different ingredients).

On Excel for Mac 2011
Thanks folks!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try

=SUMPRODUCT((C2:C100=A1)*(D2:F100>0))


Note,
Even though you're allowed to use entire column references like C:C, it is not recommended in sumproduct.
 
Upvote 0
Also

=COUNT(INDEX(1/(C:C=A1)/D:F,))

Remark:
Like Jonmo said it's not efficient to use whole columns. For ex., specify rows 2:100 or whatever you deem fit.
 
Upvote 0
One day I'll remember how to use this SUMPRODUCT...I'm not sure when.
A follow-up...
Is there an easy way to modify for when the columns are not consecutive? So when I need to check ingredients for columns C, D, E, but also H, K, N?

Thanks-
 
Last edited:
Upvote 0
You're welcome.
I just edited a follow-up with another quick one if you have a sec in regards to if the ingredient columns aren't sequential.
Thanks again much!
 
Upvote 0
If the ingredient columns are not sequential, then

=SUMPRODUCT((C2:C100=A1)*((D2:D100>0)+(F2:F100>0)+(P2:P100>0)))
 
Upvote 0
A belated thanks Jonmo1-
Much helped for what I was doing. Now to go try to remember why the SUMPRODUCT formula logically makes sense...if I can...
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

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