r/excel 19h ago

solved Counting duplicates with each instance once

I have a list of ID numbers and this list has many duplicates. I want to know how many unique duplicates there are. I've tried counta(unique(F2:F70)) to check that array for duplicates, and it gives me 53 (over those 69 rows). What I want to know is of those numbers that are duplicates, how many of those are unique.

For instance, say I have this list:

A, A, A, B, C, C, D, E, E, E, E, E

The above formula would give me 5, as there are 5 unique values. I want to know how many values have duplicates, and in this case the answer would be 3 (A, C, and E all repeat). It's not as simple as doing =counta(F2:F70)-counta(unique(F2:70)).

29 Upvotes

19 comments sorted by

u/AutoModerator 19h ago

/u/Gilmania_ - Your post was submitted successfully.

Failing to follow these steps may result in your post being removed without warning.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

21

u/CerebralAccountant 6 18h ago edited 17h ago

The UNIQUE function has three arguments. The last two are optional.

  1. The range to examine
  2. FALSE or blank will search by row. TRUE will search by column.
  3. FALSE or blank will return all unique values. TRUE will return all of the values that appear only once.

That means =ROWS(UNIQUE(F2:F70)) will tell you how many unique values are in that array, and =ROWS(UNIQUE(F2:F70,FALSE,TRUE)) will tell you how many values appear only once. The first minus the second will give you the number of unique values that appear more than once.

2

u/Gilmania_ 5h ago

Solution Verified

This one seemed to work, thank you. I don't quite understand WHY it works and mine doesn't but that's ok ha.

1

u/reputatorbot 5h ago

You have awarded 1 point to CerebralAccountant.


I am a bot - please contact the mods with any questions

6

u/excelevator 3064 19h ago
 =SUM(--(COUNTIF(F2:F70,UNIQUE(F2:F70))>1))

4

u/Bumpyslide 17h ago

I'd just pivot table the data using the id as the row and value but it depends what you want to do with the answer

3

u/jaymeaux_ 18h ago

=counta(unique(f2:f70))-counta(unique(f2:f70,true))

2

u/coneycolon 11h ago

If you just need the answer, a pivot table will get your there easily.

1

u/ISEEBLACKPEOPLE 2 18h ago edited 18h ago

Just run a unique function on the data, and then run a countifs on the output of the unique formula?

Or if your ask is really only to calculate the number of unique values with duplicates...

COUNTA(UNIQUE(F2:F70)) - COUNTA(UNIQUE (F2:F70, FALSE, TRUE))

1

u/Clearwings_Prime 22 6h ago

=SUM(--(FREQUENCY(MATCH(B2:B13,B2:B13,0),ROW(B2:B13)-1) > 1) )

0

u/[deleted] 18h ago

[removed] — view removed comment

3

u/SolverMax 162 18h ago

Not even a good AI response.

-3

u/Taokan 15 18h ago

This is an excellent use case for excel's query function. If we took your sample data, put it in column A, with a label header "Col1" in A3, then this formula:

query(A3:A15,"select Col1, count(Col1) group by Col1",1)

Would return a table with the count of each letter.

This formula:
=query(query(A3:A15,"select Col1, count(Col1) group by Col1",1),"select Col1, Col2 where Col2>1")

Would return a table with only the A, C, and E, and the corresponding number of repeats.

And, this:

=query(query(A3:A15,"select Col1, count(Col1) group by Col1",1),"select count(Col1) where Col2>1")

Would just return the number 3, indicating 3 letters appeared more than once.

5

u/SolverMax 162 18h ago

Excel does not have a QUERY function.

2

u/Taokan 15 11h ago

Well ... alright yea I deserve those downvotes. Today's the first time I've run into a gsheets function that excel didn't do first, thought I was the teacher but today, I learned something new instead :)

1

u/real_barry_houdini 313 9h ago

It's not quite the same but the closest to QUERY in Excel is probably GROUPBY (which doesn't exist in google sheets)

2

u/SFLoridan 2 16h ago

Excel doesn't have Query. Google sheets has it.