Formula to Identify Duplicates and Get Count

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,214
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need an Excel formula to find duplicates based on two columns (Region/Station) and return the count in the last occurrence. For example, there two duplicates of North/40 so the last occurrence shows 2, likewise there is 4 duplicates for East/20 so the result in the last occurrence shows 4. The ones that are unique should be empty/blank. Please help.

RegionStationResult
East20
North40
South50
East20
North402
East20
East204
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Small correction, the ones that are unique should return a 1 not empty/blank. So in the above table, only South/50 will have a 1 in the result column.
 
Upvote 0
How about this? It doesn't return the row, it returns the number in the set.

Book4
ABC
1RegionStationResult
2East200
3North400
4South500
5East201
6North402
7East204
8East206
Sheet4
Cell Formulas
RangeFormula
C2:C8C2=MAX((($A$1:A1)&($B$1:B1)=(A2&B2))*(ROW($A$1:A1))-1,0)
 
Upvote 0
Here is how I did it:
1718051874031.png


Formula in cell C2 and copy down:
Excel Formula:
=LET(x,COUNTIFS(A:A,A2,B:B,B2),IF(AND(x>1,x=COUNTIFS($A$2:$A2,A2,$B$2:$B2,B2)),x,""))
 
Upvote 0
Small correction, the ones that are unique should return a 1 not empty/blank.
In that case:

1718052030197.png


Formula in C2:
Excel Formula:
=LET(x,COUNTIFS(A:A,A2,B:B,B2),IF(x=COUNTIFS($A$2:$A2,A2,$B$2:$B2,B2),x,""))
 
Upvote 0
Joe, shouldn't the result in row 5 be 1 also, given that row 2 is identical?
 
Upvote 0
Joe, shouldn't the result in row 5 be 1 also, given that row 2 is identical?
No, only the last one.

Basically, it sounds like what they are saying is that for each unique combination (East/20, North/40, South/50), the total count should only appear on the line with the last entry for that group (regardless of how many times it occurs).
Since there are only 3 unique combinations in that example, there should only be 3 numbers in column C.

Even without the amendment to the original question, there are problems with your first response.
How did you get 6 for the last row?
 
Upvote 0
In that case:

View attachment 112530

Formula in C2:
Excel Formula:
=LET(x,COUNTIFS(A:A,A2,B:B,B2),IF(x=COUNTIFS($A$2:$A2,A2,$B$2:$B2,B2),x,""))
Works well for a regular data set like the above, but I tried to use it without the LET function (for ease of reading and evaluation) for a Excel table but it gives me the count for each row instead for the last occurrence. What am I doing wrong? Is my absolute table reference structure correct?

=IF(COUNTIFS(Table1[Region],Table1[@Region],Table1[Station],Table1[@Station])=COUNTIFS(Table1[[Region]:[Region]],Table1[@Region],Table1[[Station]:[Station]],Table1[@Station]),COUNTIFS(Table1[Region],Table1[@Region],Table1[Station],Table1[@Station]),"")
 
Last edited:
Upvote 0
Modifying Joe4 's formula, try:

Book1
ABC
1RegionStationResult
2East20 
3North40 
4South501
5East20 
6North402
7East20 
8East204
Sheet5
Cell Formulas
RangeFormula
C2:C8C2=LET(x,COUNTIFS([Region],[@Region],[Station],[@Station]), IF(x=COUNTIFS(INDEX([Region],1):[@Region],[@Region],INDEX([Station],1):[@Station],[@Station]),x,""))
 
Upvote 0

Forum statistics

Threads
1,221,811
Messages
6,162,114
Members
451,743
Latest member
matt3388

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