Count Unique Values with Specific Criteria

jfish1288

Board Regular
Joined
Jun 22, 2011
Messages
116
I have data in the following type

<table border="0" cellpadding="0" cellspacing="0" width="128"><colgroup><col style="width:48pt" span="2" width="64"> </colgroup><tbody><tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt;width:48pt" height="17" width="64">A</td> <td class="xl24" style="width:48pt" width="64">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">B</td> <td class="xl24">
</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">A</td> <td class="xl24">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">C</td> <td class="xl24">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">A</td> <td class="xl24">
</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">C</td> <td class="xl24">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">C</td> <td class="xl24">
</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">D</td> <td class="xl24">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">1</td> <td class="xl24">
</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">2</td> <td class="xl24">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">3</td> <td class="xl24">
</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">
</td> <td class="xl24">Criteria</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">2</td> <td class="xl24">
</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">3</td> <td class="xl24">Criteria</td> </tr> </tbody></table>

I need a formula that will count the number of unique values in column A that have "Criteria" in column B. In this case the desired output would be 5 (A, C, D, 2, and 3), a blank cell in column A does not need to be counted.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I have data in the following type

<TABLE cellSpacing=0 cellPadding=0 width=128 border=0><COLGROUP><COL style="WIDTH: 48pt" span=2 width=64></COLGROUP><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="WIDTH: 48pt; HEIGHT: 12.75pt" width=64 height=17>A</TD><TD class=xl24 style="WIDTH: 48pt" width=64>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>B</TD><TD class=xl24>

</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>A</TD><TD class=xl24>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>C</TD><TD class=xl24>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>A</TD><TD class=xl24>

</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>C</TD><TD class=xl24>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>C</TD><TD class=xl24>

</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>D</TD><TD class=xl24>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>1</TD><TD class=xl24>

</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>2</TD><TD class=xl24>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>3</TD><TD class=xl24>

</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>

</TD><TD class=xl24>Criteria</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>2</TD><TD class=xl24>

</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="HEIGHT: 12.75pt" height=17>3</TD><TD class=xl24>Criteria</TD></TR></TBODY></TABLE>

I need a formula that will count the number of unique values in column A that have "Criteria" in column B. In this case the desired output would be 5 (A, C, D, 2, and 3), a blank cell in column A does not need to be counted.
Try this...

Book1
ABC
2ACriteria5
3B__
4ACriteria_
5CCriteria_
6A__
7CCriteria_
8C__
9DCriteria_
101__
112Criteria_
123__
13_Criteria_
142__
153Criteria_
Sheet1

This array formula** entered in C2:

=SUM(IF(FREQUENCY(IF(B2:B15="criteria",IF(A2:A15<>"",MATCH(A2:A15,A2:A15,0))),ROW(A2:A15)-ROW(A2)+1),1))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
I can not completely wrap my head around the logic of the formula, what would you need to do to add a second criteria, say "Criteria2" in column c? So that it would count unique values in column A that have "Criteria" column B AND "Criteria2" in column C
 
Upvote 0
I suppose that might be asking a little much and I could probably get away with adding a new column checking if both criteria are met. Then I could do a count based on the new column
 
Upvote 0
I can not completely wrap my head around the logic of the formula, what would you need to do to add a second criteria, say "Criteria2" in column c? So that it would count unique values in column A that have "Criteria" column B AND "Criteria2" in column C

G2, control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(IF(A2:A15<>"",IF(B2:B15=E2,IF(C2:C15=F2,
  MATCH("~"&A2:A15,A2:A15&"",0)))),ROW(A2:A15)-ROW(A2)+1),1))

If there are no special meaning chars around the entries in the A range...
Rich (BB code):
=SUM(IF(FREQUENCY(IF(A2:A15<>"",IF(B2:B15=E2,IF(C2:C15=F2,
  MATCH(A2:A15,A2:A15,0)))),ROW(A2:A15)-ROW(A2)+1),1))

E2 and F2 house the conditions of interest regarding the ranges in column B and in column C.
 
Last edited:
Upvote 0
I can not completely wrap my head around the logic of the formula, what would you need to do to add a second criteria, say "Criteria2" in column c? So that it would count unique values in column A that have "Criteria" column B AND "Criteria2" in column C

I suppose that might be asking a little much and I could probably get away with adding a new column checking if both criteria are met. Then I could do a count based on the new column
Just add another nested IF:

=SUM(IF(FREQUENCY(IF(B2:B15="criteria",IF(C2:C15="criteria2",IF(A2:A15<>"",MATCH(A2:A15,A2:A15,0)))),ROW(A2:A15)-ROW(A2)+1),1))

Don't forget to array enter!
 
Upvote 0

Forum statistics

Threads
1,226,216
Messages
6,189,676
Members
453,563
Latest member
Aswathimsanil

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