Count unique values in a column in Excel
Categories:
Count Unique Values in an Excel Column: A Comprehensive Guide

Learn various methods to accurately count unique entries in an Excel column, from simple formulas to advanced techniques like Power Query and VBA.
Counting unique values in an Excel column is a common task for data analysis and reporting. Whether you're cleaning data, identifying distinct categories, or preparing summaries, Excel offers several powerful methods to achieve this. This article will guide you through different approaches, from straightforward formulas to more advanced tools, ensuring you can tackle any scenario.
Method 1: Using a Combination of COUNTIF and SUMPRODUCT
This method is a classic and highly effective way to count unique values directly within a worksheet using a formula. It works by checking each cell against the entire range and summing up the reciprocals of their counts. If a value appears 'n' times, it contributes '1/n' to the sum, so each unique value ultimately contributes '1' to the total.
=SUMPRODUCT(1/COUNTIF(A:A,A:A))
Formula to count unique values in column A (entire column)
For a specific range, say A2:A100
, the formula would be =SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100))
. This formula is robust but can be slow on very large datasets due to its array-like calculation. It also requires careful handling of blank cells, as COUNTIF
will count them, leading to a division by zero error if not addressed.
DIV/0!
error if there are blank cells in your range. To avoid this, use =SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100&""))
or filter out blanks before applying the formula.Method 2: Using the UNIQUE Function (Excel 365)
For users with Excel 365, the UNIQUE
function provides a much simpler and more efficient way to extract unique values. Once you have the unique list, you can simply count the number of items in that list using ROWS
or COUNTA
.
=ROWS(UNIQUE(A:A))
Counting unique values in column A using UNIQUE and ROWS functions
This formula is dynamic and will automatically update as your data changes. It's the preferred method for modern Excel versions due to its simplicity and performance. If you only want to list the unique values, simply use =UNIQUE(A:A)
in a cell, and it will spill the unique list into adjacent cells.
flowchart TD A["Input Range (e.g., A:A)"] --> B{"UNIQUE(Range)"} B --> C["Spilled Array of Unique Values"] C --> D{"ROWS(Array)"} D --> E["Count of Unique Values"]
Workflow for counting unique values using the UNIQUE function
Method 3: Using PivotTables
PivotTables are incredibly versatile for summarizing data, and they can easily count unique items. This method is particularly useful when you need to analyze unique counts alongside other data aggregations or when dealing with very large datasets where formulas might become slow.
1. Prepare Your Data
Ensure your data has a header row. Select the column (or entire dataset) you want to analyze.
2. Insert PivotTable
Go to the 'Insert' tab, then click 'PivotTable'. Choose where you want the PivotTable to be placed (new worksheet is usually best) and click 'OK'.
3. Configure PivotTable Fields
In the 'PivotTable Fields' pane, drag the column you want to count unique values from into the 'Rows' area. Then, drag the same column into the 'Values' area.
4. Change Value Field Settings
In the 'Values' area, click on the field name (e.g., 'Count of Column1'), select 'Value Field Settings...'. In the dialog box, scroll down the 'Summarize value field by' list and choose 'Distinct Count'. Click 'OK'.