Counting Unique Values based on a Criteria

smalik

Board Regular
Joined
Oct 26, 2006
Messages
180
Office Version
  1. 365
Platform
  1. Windows
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.

1623365972182.png
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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


1623367727578.png
 
Upvote 0
Awesome... Thank you.

This works. I never thought of the "=1/COUNTIFS(C:C,C4,B:B,B4)" formula.
 
Upvote 0
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.
 
Upvote 0
Solution
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?
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,239
Members
448,555
Latest member
RobertJones1986

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