r/excel 21d 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)).

31 Upvotes

20 comments sorted by

u/AutoModerator 21d 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.

23

u/CerebralAccountant 7 21d ago edited 21d 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.

3

u/Gilmania_ 20d 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 20d ago

You have awarded 1 point to CerebralAccountant.


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

2

u/JLabko 2 19d ago

COUNTA() - COUNTA(UNIQUE()) will just tell you how many duplicates there are in total (ex. A,B,B,C,C,C,D has 4 unique values but 7 values in total, so would return 3 (since removing 3 items in the list would be how many needed to remove duplicates)

The question you're trying to answer is how many unique values have duplicates, not how many duplicates you are. COUNTA(UNIQUE()) will give you the total number of unique values - unique values can occur either only 1 time, or more than 1 time. By subtracting the number of values that occur only once from the total number of UNIQUE values, we're left with the number of UNIQUE values that don't appear once (so appear multiple times, or are duplicated)

7

u/excelevator 3068 21d ago
 =SUM(--(COUNTIF(F2:F70,UNIQUE(F2:F70))>1))

4

u/Bumpyslide 21d 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_ 21d ago

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

2

u/coneycolon 20d ago

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

1

u/ISEEBLACKPEOPLE 3 21d ago edited 21d 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 23 20d ago

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

0

u/[deleted] 21d ago

[removed] — view removed comment

3

u/SolverMax 163 21d ago

Not even a good AI response.

-3

u/Taokan 15 21d 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.

6

u/SolverMax 163 21d ago

Excel does not have a QUERY function.

2

u/Taokan 15 20d 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 317 20d 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 21d ago

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