COUNTIFS alternative

kalmar27615

New Member
Joined
May 12, 2014
Messages
7
Hello everyone, I have the following issue I'm hoping you can help me with:

I am trying to count the number of occurrences with 2 criteria: =COUNTIFS(B:B,"Birmingham",C:C,"PASSED")

AL001Birmingham
AL001CV
AL001PHYPASSED
AL001No
AL001Vendor
AL002BirminghamPASSED
AL002PHY
AL002Vendor
AL003Birmingham
AL003DAPASSED

<tbody>
</tbody>

The location of the "PASSED" entry is dynamic and is not always directly across from "Birmingham" which is why I am not getting the correct results. Is there a solution to this? Thank you all in advance!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
A
B
C
D
E
1
AL001Birminghamcriteria
2
AL001CVBirmingham+ PASSED
3
AL001PHYPASSED
6​
4
AL001No
5
AL001Vendor
6
AL002BirminghamPASSED
7
AL002PHY
8
AL002Vendor
9
AL003Birmingham
10
AL003DAPASSED

<tbody>
</tbody>


E3=SUMPRODUCT((B1:B10=B1)+(C1:C10=C3))
 
Upvote 0
A
B
C
D
E
1
AL001Birminghamcriteria
2
AL001CVBirmingham+ PASSED
3
AL001PHYPASSED
6​
4
AL001No
5
AL001Vendor
6
AL002BirminghamPASSED
7
AL002PHY
8
AL002Vendor
9
AL003Birmingham
10
AL003DAPASSED

<tbody>
</tbody>


E3=SUMPRODUCT((B1:B10=B1)+(C1:C10=C3))
Thank you, but the result I'm looking for is 3 (for 3 "PASSED" sites (AL001, AL002 and AL003) in Birmingham
 
Upvote 0
Based on your table, it appears that each "occurrence" has the same number in column A. So if lines 1:5 have Birmingham in column B somewhere, and 1:5 have PASSED in column C somewhere, you want to count it. Repeat for each group in column A.

If so, try:

ABCD
1AL001Birmingham3
2AL001CV
3AL001PHYPASSEDBirmingham
4AL001No
5AL001Vendor
6AL002BirminghamPASSED
7AL002PHY
8AL002Vendor
9AL003Birmingham
10AL003DAPASSED

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet8

Array Formulas
CellFormula
D1{=SUM(--(COUNTIFS(A1:A10,IF(B1:B10=D3,A1:A10,"^^^"),C1:C10,"PASSED")>0))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



D1 is an array formula, confirm with Control+Shift+Enter. The city name is in D3. Let me know if this is workable.
 
Upvote 0
Thank you Eric, this worked to an extent, but the way I have the table setup is there is another column with more variables and the formula returns 4 instead of 3 in this case:

ABCDE
1CivilAL001Birmingham 4
2CivilAL001CV
3CivilAL001PHYPASSEDBirmingham
4CivilAL001No
5CivilAL001Vendor
6CivilAL002BirminghamPASSED
7CivilAL002PHY
8CivilAL002Vendor
9CivilAL003Birmingham
10CivilAL003DA
11ElecAL003Birmingham
12ElecAL003DA
13ElecAL003DAPASSED

<colgroup><col span="3"><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
What do you want the answer to be in new table, 3 or 4? Would you be able to clarify again what you are wanting?
 
Upvote 0
What do you want the answer to be in new table, 3 or 4? Would you be able to clarify again what you are wanting?
The answer I am looking for is 3. as in post #5: I have 3 sites (column B), some "Civil", some "Elec" and some are both. I need to count how many "PASSED" there are in column D for sites that have "Birmingham" for every group of sites
 
Upvote 0
The issue is that for group AL003, Birmingham occurs twice. It appears you only want to count once for each ALxxx group.

Try this:

ABCDE
1CivilAL001Birmingham3
2CivilAL001CV
3CivilAL001PHYPASSEDBirmingham
4CivilAL001No
5CivilAL001Vendor
6CivilAL002BirminghamPASSED
7CivilAL002PHY
8CivilAL002Vendor
9CivilAL003Birmingham
10CivilAL003DA
11ElecAL003Birmingham
12ElecAL003DA
13ElecAL003DAPASSED

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
E1{=SUM(--(COUNTIFS(B1:B13,IF((C1:C13=E3)*IFERROR(MATCH(B1:B13&"|"&C1:C13,B1:B13&"|"&C1:C13,0)=ROW(C1:C13)-ROW(C1)+1,0),B1:B13,"^^^"),D1:D13,"PASSED")>0))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



This should work for you. It's a bit more complicated though. I might step back and try a different approach. But see how this goes for now.
 
Upvote 0
Here is a different approach. I haven't thoroughly tested this yet, but it looks good so far.


Book1
ABCDEF
1
2CivilAL001Birmingham33
3CivilAL001CV
4CivilAL001PHYPASSEDBirmingham
5CivilAL001No
6CivilAL001Vendor
7CivilAL002BirminghamPASSED
8CivilAL002PHY
9CivilAL002Vendor
10CivilAL003Birmingham
11CivilAL003DA
12ElecAL003Birmingham
13ElecAL003DA
14ElecAL003DAPASSED
Sheet1
Cell Formulas
RangeFormula
E2{=SUM(--(COUNTIFS(B2:B14,IF((C2:C14=E4)*IFERROR(MATCH(B2:B14&"|"&C2:C14,B2:B14&"|"&C2:C14,0)=ROW(C2:C14)-ROW(C2)+1,0),B2:B14,"^^^"),D2:D14,"PASSED")>0))}
F2{=SUM(IF(FREQUENCY(IF(C2:C14=E4,ROW(C2:C14)),IF(B1:B15<>B2:B16,ROW(B1:B15)))*FREQUENCY(IF(D2:D14="PASSED",ROW(C2:C14)),IF(B1:B15<>B2:B16,ROW(B1:B15))),1))}
Press CTRL+SHIFT+ENTER to enter array formulas.


I don't know which is better, but FREQUENCY often works faster. The FREQUENCY^2 function requires slightly different ranges, adding a row before. Interesting problem, I'll look at it some more.
 
Upvote 0
The issue is that for group AL003, Birmingham occurs twice. It appears you only want to count once for each ALxxx group.


Array Formulas
CellFormula
E1{=SUM(--(COUNTIFS(B1:B13,IF((C1:C13=E3)*IFERROR(MATCH(B1:B13&"|"&C1:C13,B1:B13&"|"&C1:C13,0)=ROW(C1:C13)-ROW(C1)+1,0),B1:B13,"^^^"),D1:D13,"PASSED")>0))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



This should work for you. It's a bit more complicated though. I might step back and try a different approach. But see how this goes for now.

That is correct, "Birmingham" could occur twice, but each group could also have "Civil" and "Elec" within the same group which will have their own "PASSED" that needs to be counted. Sorry, my previous post did not include the "PASSED" for AL003 "Civil" group. There also could be "FAILED" within the same group as well as "PASSED" ("FAILED" for AL003 Civil and "PASSED" for AL003 Elec and visa-versa)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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