Counting Unique Values based on a Criteria

smalik

Board Regular
Joined
Oct 26, 2006
Messages
125
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

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
Joined
May 26, 2018
Messages
229
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
 

smalik

Board Regular
Joined
Oct 26, 2006
Messages
125
Office Version
  1. 365
Platform
  1. Windows
Awesome... Thank you.

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

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
4,766
Office Version
  1. 365
  2. 2010
Platform
  1. Windows

ADVERTISEMENT

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

smalik

Board Regular
Joined
Oct 26, 2006
Messages
125
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Feb 15, 2002
Messages
4,766
Office Version
  1. 365
  2. 2010
Platform
  1. Windows

ADVERTISEMENT

What happened when you tried that?
 

smalik

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

Watch MrExcel Video

Forum statistics

Threads
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.
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
Top