Features of !SEMTools
↑ Navigate Excel tasks and !SEMTools add-in features ↑

Count unique values in Excel

, creator of !SEMToolsUpdated 6 min readTopics: Numbers and calculations
Count how many times each value repeats and number each occurrence in Excel
«paris» and «Paris» count as the same value. The second column numbers the occurrences in order.

In a customer column, Anna may appear on ten orders. A distinct count includes Anna once. A frequency report gives Anna a row with a count of ten. Decide which result you need before building the report.

A unique list in Excel 2013

In an older version, replace UNIQUE with a legacy array formula. For Anna, Bob, Anna, Cleo in A2:A5, J2:J4 returns Anna, Bob, Cleo. Blank cells in A2:A8 are skipped, first-occurrence order is preserved and comparisons ignore case. COUNTIF treats * and ? as wildcards, so this version is not suitable for source values containing those characters.

J2, enter with Ctrl+Shift+Enter and fill down. Keep J1 empty. A2:A8 contains the source values:

=IFERROR(INDEX($A$2:$A$8,MATCH(0,IF($A$2:$A$8<>"",COUNTIF($J$1:J1,$A$2:$A$8),1),0)),"")

K2, Enter, fill down beside the J list:

=IF(J2="","",COUNTIF($A$2:$A$8,J2))

Count unique values with a formula

For a filled range in Excel 2021 or later, COUNTA counts the entries returned by UNIQUE:

=COUNTA(UNIQUE(A2:A100))

In older versions, the classic formula works. COUNTIF counts how many times each value occurs, 1 divided by this count gives fractions that add up to exactly 1 for each unique value, and SUMPRODUCT adds them:

=SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100))
How many unique values
D2=COUNTA(UNIQUE(A2:A7))
ABCD
1CustomerFormulaUnique count
2Anna=COUNTA(UNIQUE(A2:A7))3=COUNTA(UNIQUE(A2:A7))
3Bob=SUMPRODUCT(1/COUNTIF(A2:A7,A2:A7))3=SUMPRODUCT(1/COUNTIF(A2:A7,A2:A7))
4Anna=SUMPRODUCT((A2:A8<>"")/COUNTIF(A2:A8,A2:A8&""))3=SUMPRODUCT((A2:A8<>"")/COUNTIF(A2:A8,A2:A8&""))
5Cleo=SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))#DIV/0!=SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))
6Bob
7Anna
8

A2:A7 has 6 names but only 3 different customers. A8 is empty: the classic SUMPRODUCT(1/COUNTIF) over A2:A8 returns #DIV/0!, the version with (A2:A8<>"") and &"" handles blanks.

Use the third result in the table when the source includes empty cells. The numerator excludes blanks and the denominator counts each remaining customer.

How to count cells with the same value

To see how many times a particular value occurs, put this formula next to the column and fill it down:

=COUNTIF($A$2:$A$100,A2)
Count cells with the same value
B2=COUNTIF($A$2:$A$7,A2)
AB
1CustomerTimes
2Anna3=COUNTIF($A$2:$A$7,A2)
3Bob2=COUNTIF($A$2:$A$7,A3)
4Anna3=COUNTIF($A$2:$A$7,A4)
5Cleo1=COUNTIF($A$2:$A$7,A5)
6Bob2=COUNTIF($A$2:$A$7,A6)
7Anna3=COUNTIF($A$2:$A$7,A7)

Every row shows how many times its value occurs; repeated values repeat their count. For one line per value, use the formula below.

Each row gets the number of occurrences of its value. The downside is that repeated values get the same number many times, so you’ll still need to remove duplicates to get a clean list.

In Excel 365, one formula builds the whole report: the list of unique values with their counts next to them:

=LET(u,UNIQUE(A2:A100),HSTACK(u,COUNTIF(A2:A100,u)))
Unique values with their counts (Excel 365)
C2=LET(u,UNIQUE(A2:A7),HSTACK(u,COUNTIF(A2:A7,u)))
ABCD
1CustomerCustomerCount
2AnnaAnna=LET(u,UNIQUE(A2:A7),HSTACK(u,COUNTIF(A2:A7,u)))3
3BobBob2
4AnnaCleo1
5Cleo
6Bob
7Anna

UNIQUE builds the list, COUNTIF counts each value, and HSTACK puts the two columns side by side. GROUPBY(A2:A7,A2:A7,COUNTA) gives the same report, sorted and with a total row.

And in the latest Excel 365 versions, the GROUPBY function does the same and can also sort the result:

=GROUPBY(A2:A100,A2:A100,COUNTA)
ValueCount
laptop4
monitor2
keyboard1

These are dynamic array formulas: they spill the result into as many rows as needed.

Count unique values with a pivot table

  • Select the column with its header and go to Insert → PivotTable → OK.
  • Drag the field to Rows, and then drag the same field to Values. Excel switches it to Count automatically for text.
  • To count distinct values in a pivot, check Add this data to the Data Model when creating it, and choose Distinct Count in Value Field Settings.

It works well for a report you’ll update, but it’s a lot of clicks for a quick look.

Count repeated cells with !SEMTools

That’s why the Fast pivot table tool was born in !SEMTools. It does just one thing, a summary with counting and summing, but does it as fast as possible, without asking unnecessary questions.

Path: CHANGE → Range → Fast pivot table → SUM. With one column selected, it counts how many times each value occurs.

In the example, the cells contain one letter each, but in reality it can be any repeated data. Select the column and click the procedure: it groups identical cells and outputs their counts to a separate sheet. No formulas, no pivot settings:

Merge identical cells and sum the other columns

When you need a quick summary with the sums of certain metrics, for example clicks and costs by keyword, select the columns and run the same procedure. There can be any number of metric columns. Empty and text values among the numbers are skipped automatically.

Important: the procedure groups by the leftmost column of the selected range and sums all the columns to the right of it, so you may need to arrange the data accordingly. It also doesn’t keep the source formatting, for the sake of speed on large datasets.

Fast pivot table in Excel: SUM, MIN and MAX by key
Sales grouped by city without a PivotTable: total, minimum and maximum, one click each.

Use SUM, MIN or MAX in the same menu for the aggregate you need.

Why the unique count is wrong: common mistakes

  • The same values are counted separately. They differ in extra spaces, case or invisible characters. Remove extra spaces first. Phrases with a different word order are implicit duplicates and need normalization.
  • The classic formula returns #DIV/0!. The range contains empty cells: use the version with &"" shown above.
  • The pivot table shows Sum instead of Count. The column contains numbers: change the field to Count in Value Field Settings.

Count repeated values and build a quick summary with sums in a couple of clicks, without formulas or pivot table settings.
!SEMTools solves this and hundreds of other tasks right in Excel!

Summary: which way to count unique values

I hope you found what you were looking for on this page and were able to count the unique values in your data. For a single number, COUNTA(UNIQUE) or SUMPRODUCT(1/COUNTIF) is enough. For a report with counts, use UNIQUE with COUNTIF or GROUPBY in Excel 365, or a pivot table. For a quick look at any list, the !SEMTools fast pivot does it in one click. The reverse task — putting the values of one cell on separate rows while keeping the category — is solved by “Unpivot and split 2nd column” in the same menu.

You may also be interested in how to find duplicates in Excel and in other statistical metrics: occurrence numbers, shares and ABC analysis.