# Counting Unique Values based on a Criteria

#### smalik

##### Board Regular
Is there a formula that can count unique values in one column based on a criteria in a different column?

In the example below, I only want to count 07SPE-1 only once for each Pol_Dept field

I have 52,000+ records with Pol_Dept. numbered from 1-9 and letters A-G. However, I don't think that matters. Once I figure out the right formula, the rest is easy.

Hopefully, I explained my question clearly.

Sorry, working through my office computer that does not let me allow to have addons without admin rights. Hopefully, the image helps.

### Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

#### Saba Sabaratnam

##### Board Regular
You could use helper column to do it.

Enter the following formula in D4 and copy it down

=1/COUNTIFS(C:C,C4,B:B,B4)

Then enter the following formula in G4 and copy it down

=SUMIFS(D:D,B:B,F4)

Kind regards

Saba

#### smalik

##### Board Regular
Awesome... Thank you.

This works. I never thought of the "=1/COUNTIFS(C:C,C4,B:B,B4)" formula.

You are welcome

#### Dave Patton

##### Well-known Member

Try Excel 365's Unique functions

Unique.xlsm
ABCDEF
1
2
3Pol_deptCust_recPol_deptCust_rec
4207SPE_122
5207SPE_131
621169E_1
7307SPE_1
8307SPE_1
9307SPE_1
10307SPE_1
1b
Cell Formulas
RangeFormula
E4:E5E4=SORT(UNIQUE(B4:B10))
F4:F5F4=ROWS(UNIQUE(FILTER(C\$4:C\$10,B\$4:B\$10=E4)))
Dynamic array formulas.

#### smalik

##### Board Regular
Try Excel 365's Unique functions

Unique.xlsm
ABCDEF
1
2
3Pol_deptCust_recPol_deptCust_rec
4207SPE_122
5207SPE_131
621169E_1
7307SPE_1
8307SPE_1
9307SPE_1
10307SPE_1
1b
Cell Formulas
RangeFormula
E4:E5E4=SORT(UNIQUE(B4:B10))
F4:F5F4=ROWS(UNIQUE(FILTER(C\$4:C\$10,B\$4:B\$10=E4)))
Dynamic array formulas.

Is the formula in Column E necessary? Can it be a typed in value?

#### Dave Patton

##### Well-known Member

What happened when you tried that?

#### smalik

##### Board Regular
You could use helper column to do it.

Enter the following formula in D4 and copy it down

=1/COUNTIFS(C:C,C4,B:B,B4)

Then enter the following formula in G4 and copy it down

=SUMIFS(D:D,B:B,F4)

Kind regards

Saba

View attachment 40577
This works fine with small data set but when I tried it on my actual data (over 50,000 rows), I get a #Div/0! error. Any idea why?

#### smalik

##### Board Regular
What happened when you tried that?
Last night when I did it, I was getting a circular error message. I did it again this AM and it worked fine. I guess I must be doing something wrong. Thanks.

Replies
3
Views
47
Replies
5
Views
204
Replies
2
Views
44
Replies
2
Views
120
Replies
19
Views
258

1,132,895
Messages
5,655,844
Members
418,246
Latest member
VerticalChris

### 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.

### Which adblocker are you using?

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

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