Count Unique Values in Excel
Upload a sheet or paste a list, pick a column, and get the number of distinct values plus a table of each value and its count.
Updated
How to count unique values
- Choose your file, or paste cells copied from Excel or Google Sheets and select Use pasted data.
- Leave First row is a header ticked if row 1 holds column names.
- Under Columns to compare, select the column to count, such as City or Product. Select two or more columns to count combinations, such as each City and Product pair. With none selected, whole rows are counted.
- Tick Match case if Paris and PARIS should be counted separately.
- Read the result. Distinct values is how many different values there are. Values that appear once is how many of them have no repeat. Rows counted is how many rows had something in the chosen columns.
- Select Download .xlsx or Download .csv to save the table.
The table lists each value with a Count column, most frequent first. Empty cells are skipped. Spaces at the start and end of a cell are ignored, so “Lyon” and “Lyon “ count as one value.
Unique or distinct
The two words are often used for the same thing, and they mean different counts. Take this list of five cities: Paris, Lyon, Paris, Nice, Lyon.
- Distinct values: 3 (Paris, Lyon, Nice). Each different value is counted once.
- Values that appear once: 1 (Nice). Paris and Lyon both repeat.
Most people who search for a unique count want the distinct count. Check which one your report needs.
Count unique values in Excel itself
Excel 365 and Excel 2021
=COUNTA(UNIQUE(A2:A100))
UNIQUE returns each different value once and COUNTA counts them. If the range includes empty cells, the blank is returned as one extra value. Remove it with FILTER:
=COUNTA(UNIQUE(FILTER(A2:A100, A2:A100<>"")))
To count the values that appear exactly once, set the third argument of UNIQUE to TRUE:
=COUNTA(UNIQUE(A2:A100, , TRUE))
Older versions of Excel
=SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100))
COUNTIF returns, for every cell, how many times its value appears. A value that appears three times gives three results of 1/3, which add up to 1. The total is the distinct count.
This formula fails when the range has an empty cell. COUNTIF returns 0 for the blank, and 1/0 produces #DIV/0!. This version skips empty cells:
=SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&""))
Both formulas are slow on tens of thousands of rows, because every cell is compared with every other cell.
With a pivot table
- Select the data and go to Insert > PivotTable.
- Tick Add this data to the Data Model, then select OK.
- Drag the field into Values.
- Select the field, open Value Field Settings, and choose Distinct Count.
Distinct Count is only listed when the pivot table uses the Data Model.
A tally of every value
To get the same table this page produces, list the distinct values and count each one:
=UNIQUE(A2:A100)
=COUNTIF($A$2:$A$100,D2)
The first formula goes in D2 and spills down. The second goes in E2 and is filled down beside it.
In Google Sheets
=COUNTUNIQUE(A2:A100)
COUNTUNIQUE returns the distinct count and ignores empty cells. For a tally, =UNIQUE(A2:A100) with COUNTIF beside it works as it does in Excel.
Which method to use
| Situation | Best option |
|---|---|
| A quick count from a file you were sent | This page |
| You want each value with its count | This page, or UNIQUE with COUNTIF |
| The count must update as data changes, Excel 365 or 2021 | =COUNTA(UNIQUE()) |
| Excel 2019 or earlier | The SUMPRODUCT and COUNTIF formula |
| Distinct counts per group, such as customers per region | Pivot table with Distinct Count |
| You want to see which rows repeat | Find duplicates |
Mistakes to avoid
- Counting the header. Start the range at the first data row, A2 and down, or the column name is counted as a value.
- Forgetting empty cells. They raise the UNIQUE count by one and break the SUMPRODUCT formula.
- Expecting case to matter. UNIQUE and COUNTIF treat Paris and PARIS as the same value. This tool does too unless Match case is ticked.
- Stray spaces. “Lyon “ with a trailing space is a separate value in Excel. Clean the column with TRIM, or with find and replace, before counting.
Limits
- 50 MB per file. Formats: .xlsx, .xls, .xlsm, .csv, .tsv, .txt and .ods.
- One sheet is counted at a time. Pick it from the tabs above the options.
- The file is read on your device and is not uploaded.
- The download is the table of values and counts, without formulas or formatting.
Questions
How do I count unique values in Excel?
In Excel 365 and Excel 2021, use =COUNTA(UNIQUE(A2:A100)). In older versions, use =SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100)), which needs a range with no empty cells.
What is the difference between unique and distinct values?
Distinct values are all the different values in a list, each counted once. Unique values, in the strict sense, are the ones that appear exactly one time. In the list A, A, B, C there are three distinct values and two unique ones. Many people say unique for both, so this tool reports both numbers.
How do I count how many times each value appears?
The table in the tool above lists every value with its count. In Excel, put the distinct values in a column with =UNIQUE(A2:A100), then use =COUNTIF($A$2:$A$100,D2) next to each one. The COUNTIF page explains the arguments.
Why does my SUMPRODUCT formula return #DIV/0!?
The range contains an empty cell. COUNTIF returns 0 for it and the formula divides by that zero. Use =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")), which skips empty cells.
Can a pivot table count distinct values?
Yes. Tick Add this data to the Data Model when you create the pivot table. Then open Value Field Settings for the field and choose Distinct Count at the bottom of the list.
How do I count unique values in Google Sheets?
Use =COUNTUNIQUE(A2:A100). It ignores empty cells. =COUNTA(UNIQUE(A2:A100)) works there too.