Countif from a Pivot Table for one unique value being greater than another

excelhelp1a

New Member
Joined
Apr 26, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a pivot table in which I need to count the number of occurrences that certain criteria are met. The data is below, the criteria that I need met is this: Green is greater than 0, the state is CA, and at least one other item (Red/Blue) has a value greater than 0. I think I need to do some sort of countif and sumproduct but am not sure how to get the desired result. Any information is super appreciated!

StateRedBlueGreenGrand Total
CA
1​
2​
3​
6​
CA
0​
0​
3​
3​
CA
0​
0​
1​
1​
NM
1​
3​
2​
6​
NM
1​
2​
1​
4​
CA
1​
2​
3​
6​
NM
1​
2​
1​
4​
NY
3​
4​
2​
9​
NY
2​
1​
1​
4​
CA
1​
1​
0​
2​
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the MrExcel forum!

Try:

Book1
ABCDEFG
1StateRedBlueGreenGrand TotalCount
2CA12362
3CA0033
4CA0011
5NM1326
6NM1214
7CA1236
8NM1214
9NY3429
10NY2114
11CA1102
Sheet13
Cell Formulas
RangeFormula
G2G2=SUMPRODUCT(--(A2:A11="CA"),--(D2:D11>0),--(B2:B11+C2:C11>0))
 
Upvote 0
Solution
Welcome to the MrExcel forum!

Try:

Book1
ABCDEFG
1StateRedBlueGreenGrand TotalCount
2CA12362
3CA0033
4CA0011
5NM1326
6NM1214
7CA1236
8NM1214
9NY3429
10NY2114
11CA1102
Sheet13
Cell Formulas
RangeFormula
G2G2=SUMPRODUCT(--(A2:A11="CA"),--(D2:D11>0),--(B2:B11+C2:C11>0))
Thanks Eric, this is super helpful! To expand upon this let's say there are 5 columns of colors (Red, Blue, Green, Yellow, White) what would the formula be if I were to want to have Red be >0 and then at least 2 other colors be >0
 
Upvote 0
Consider:

Book1
ABCDEFGHI
1StateRedBlueGreenYellowWhiteGrand TotalCount
2CA1231163
3CA0030133
4CA0011013
5NM132006
6NM121114
7CA123016
8NM121104
9NY342009
10NY211114
11CA110012
Sheet13
Cell Formulas
RangeFormula
I2I2=SUMPRODUCT(--(A2:A11="CA"),--(B2:B11>0),--((C2:C11>0)+(D2:D11>0)+(E2:E11>0)+(F2:F11>0)>=2))
I3I3=SUMPRODUCT(--(A2:A11="CA"),--(B2:B11>0),--(MMULT(--(C2:F11>0),{1;1;1;1})>=2))
I4I4=SUMPRODUCT(--(A2:A11="CA"),--(MMULT(--(B2:F11>0),{10;1;1;1;1})>=12))


The I2 formula is just an extension of the existing formula, and it's probably the easiest to understand. The I3 formula shows a way to shorten that formula by using MMULT. It requires that the Blue-White columns are all adjacent to each other though.

The I4 formula is a way I found to include the B column in the MMULT as well, shortening it even further. But I admit it's a bit cutesy, and harder to understand/maintain for someone looking at it cold.

Let me know if you have any questions. Good luck!
 
Upvote 0
Eric this is exactly what I was looking for! Hoping to expand it a bit further though. Let's say each state has a customer ID associated with it. Another table in the workbook denotes whether that specific ID should be counted or not. Is there a way for me to reference that second table check whether or not the above conditions are met AND the customer ID should be counting?

StateIDRedBlueGreenYellowWhiteGrand Total
CA1123118
CA2003014
CA3001102
NM4132006
NM5121116
CA6123017
NM7121105
NY8342009
NY9211116
CA10110013


IDCount
1​
Yes
2​
No
3​
Yes
4​
Yes
5​
No
6​
No
7​
Yes
8​
No
9​
Yes
10​
No

Thank you so much!!
 
Upvote 0
Try this:

Book1
ABCDEFGHIJKLMN
1StateIDRedBlueGreenYellowWhiteGrand TotalCountIDCount
2CA112311611Yes
3CA200301312No
4CA300110113Yes
5NM41320064Yes
6NM51211145No
7CA61230166No
8NM71211047Yes
9NY83420098No
10NY92111149Yes
11CA1011001210No
Sheet4
Cell Formulas
RangeFormula
J2J2=SUMPRODUCT(--(A2:A11="CA"),--(COUNTIFS($M$2:$M$11,$B$2:$B$11,$N$2:$N$11,"Yes")>0),--(C2:C11>0),--((D2:D11>0)+(E2:E11>0)+(F2:F11>0)+(G2:G11>0)>=2))
J3J3=SUMPRODUCT(--(A2:A11="CA"),--(COUNTIFS($M$2:$M$11,$B$2:$B$11,$N$2:$N$11,"Yes")>0),--(C2:C11>0),--(MMULT(--(D2:G11>0),{1;1;1;1})>=2))
J4J4=SUMPRODUCT(--(A2:A11="CA"),--(COUNTIFS($M$2:$M$11,$B$2:$B$11,$N$2:$N$11,"Yes")>0),--(MMULT(--(C2:G11>0),{10;1;1;1;1})>=12))


It's the same 3 formulas as before, just with an added COUNTIFS condition.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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