The quickest way to get a unique count in an Excel pivot table is to add your data to the Data Model and then use the “Distinct Count” summary function. In practice, this means: select your data, go to Insert > PivotTable, check the box for “Add this data to the Data Model,” then drag the field you want to count into the Values area and change its value field settings from “Count” to “Distinct Count.”
Why a Normal Pivot Table Can’t Count Unique Values
A standard pivot table, without the Data Model, only offers summary functions like Sum, Count, Average, Max, Min, and a few others. The “Count” function counts every cell that contains a number, not every distinct item. If you have a list of orders and want to know how many unique customers placed orders, a regular pivot table will count each order row, not each customer. This is a common frustration: you drag a customer name field into the Values area, see a count of 500, but you know you only have 120 distinct customers.
The reason is that traditional pivot tables are designed to aggregate data in a simple, predictable way. They don’t perform a distinct count because doing so requires more complex processing. Microsoft added the Data Model (also known as the Power Pivot engine) to Excel 2013 and later, and it is this engine that supports the distinct count function.
Step-by-Step: Create a Pivot Table with Distinct Count
Here is the exact process for Excel for Microsoft 365 on Windows (the steps are the same on Mac, but the dialog boxes look slightly different):
- Click anywhere inside your data range or table.
- Go to Insert > PivotTable.
- In the Create PivotTable dialog, choose where you want the pivot table placed (New Worksheet is usually best).
- Check the box that says “Add this data to the Data Model” – this is the critical step.
- Click OK. A blank pivot table appears.
- In the PivotTable Fields pane, drag a field (for example, “Customer”) into the Rows area if you want to see each unique customer, or leave it blank if you just want a single total.
- Drag the same field (or another field you want to count uniquely) into the Values area.
- Click the drop-down arrow next to the field name in the Values area, then select Value Field Settings.
- Scroll down in the “Summarize value field by” list and select Distinct Count.
- Click OK.
If you don’t see “Distinct Count” in the list, it means you did not add the data to the Data Model. Close the pivot table, delete it, and start again, making sure to check that box.
Alternative: Use a Helper Column with a Formula
If you cannot use the Data Model (for example, you are working with an older Excel version or a shared workbook that doesn’t support it), you can add a helper column to your source data. The formula below will mark the first occurrence of each unique value as 1, and subsequent occurrences as 0. Then you can sum that column in a regular pivot table.
Assume your data is in A2:A100 (the values you want to count uniquely). In B2, enter:
=IF(COUNTIF($A$2:A2,A2)=1,1,0)
Drag this formula down. It uses a mixed reference ($A$2:A2) so that the range expands as you copy it down. For each row, it counts how many times the value in A2 has appeared so far. If it’s the first occurrence, it returns 1; otherwise 0. Then, in your pivot table, add this helper column to the Values area and use the Sum function. The sum will equal the number of distinct values.
This method works in any Excel version, but it adds a column to your source data and requires you to refresh the formula if you add new rows. Also, if your data is in a table, the formula will auto-fill.
Using the UNIQUE Function for a Quick Count
If you don’t need a pivot table at all, you can use the UNIQUE function (available in Excel 2021 and Microsoft 365) to get a list of distinct values, and then wrap it in COUNTA to count them. For example, with values in A2:A100, enter:
=COUNTA(UNIQUE(A2:A100))
This returns the number of distinct text and number entries in that range. Note that COUNTA counts non-empty cells, so if the range includes blank cells, UNIQUE will ignore them (it does not return blanks), so the count is accurate. This is the simplest method for a one-off count, but it does not give you a pivot table with other aggregations.
Common Pitfalls and How to Avoid Them
Several issues can trip you up when trying to get a distinct count:
- Distinct Count option is grayed out or missing: This almost always means the data was not added to the Data Model. Recreate the pivot table and check the box.
- Blank cells: In a distinct count, blank cells are not counted. If you want to count blanks as a distinct value, you’ll need to replace them with a placeholder like “(blank)” before creating the pivot table.
- Trailing spaces: “John” and “John ” are treated as two different values. Use the TRIM function to clean your data first if you suspect this.
- Numbers vs. text: The distinct count treats numbers and text separately. If you have a column of numeric IDs stored as text, they will be counted as text, not numbers. Ensure consistent formatting.
- Data Model limits: The Data Model can handle large datasets, but if you are working with millions of rows, performance may slow. The distinct count is computed at refresh time, so be patient.
Comparing Distinct Count to Other Counting Methods
It’s easy to confuse “distinct count” with “unique count” – they are the same thing. But there is also “count” (all non-empty cells) and “count numbers” (only numeric cells). Here’s a quick comparison:
- Count: Counts every non-empty cell, including duplicates. In a pivot table, this is the default for numeric fields.
- Distinct Count: Counts each unique value only once, ignoring duplicates. This is what you get from the Data Model.
- Count Numbers: Counts only cells that contain numbers, ignoring text and blanks.
For example, if you have a list of 10 orders with 3 different customers, “Count” would give 10, “Distinct Count” would give 3, and “Count Numbers” would give 10 if all order IDs are numeric.
Frequently Asked Questions
Can I use distinct count in a regular pivot table without the Data Model?
No. The distinct count function is only available when you add your data to the Data Model. If you are using Excel 2013 or later, you can do this by checking the box in the Create PivotTable dialog. If you are on an older version, you must use a helper column or the UNIQUE function.
Does distinct count count blank cells?
No, blank cells are not counted as a distinct value. If you need to count blanks as a distinct category, replace them with a string like “(blank)” in your source data before creating the pivot table.
Why does my distinct count change when I refresh the pivot table?
If your source data changes (rows added, removed, or modified), the distinct count will update on refresh. That’s normal. Also, if you have filtered the pivot table, the distinct count will only consider the visible rows, which can change the result.
Can I use distinct count in a pivot chart?
Yes, pivot charts use the same data as the pivot table, so if you create a pivot chart from a pivot table that uses distinct count, the chart will reflect those values. However, if you try to create a chart directly from a data range (not a pivot table), you won’t have the distinct count option.
Is there a way to get distinct count in Power Pivot?
Yes, Power Pivot (the Excel add-in) also supports distinct count in its DAX formulas. For example, you could use DISTINCTCOUNT(Table[Column]) in a measure. This is more advanced but gives you more flexibility if you are building a data model.
Performance and Large Data Sets
When working with very large datasets (hundreds of thousands of rows), the Data Model distinct count can be slower than a simple count because it must compare each value against all others. To speed things up, consider these tips:
- Use Excel Tables (Ctrl+T) for your source data so that the pivot table range automatically expands.
- Remove any unnecessary columns from the data model to reduce memory usage.
- If you are using the UNIQUE function, be aware that it returns an array that spills into adjacent cells. If you have a very large range, this can be memory-intensive.
- For millions of rows, consider using Power Pivot directly, as it is optimized for large data.
In most real-world scenarios, the distinct count via Data Model is fast enough. If you notice lag, try refreshing the pivot table less frequently or using a helper column instead.
Related
- By Means of an Update? Meaning & Real Usage
- Windows Ctrl Shortcuts: The Complete List
- Speed and Intersection Safety Cameras: How They Work
Try it: the Percentage Formula Generator: percent of, percent change, increase and decrease, with the formula.
More in Charts & pivot tables
- Pie Chart Creator in Excel: Make and Format a ChartExcel has a built-in pie chart creator: select a category-and-value table, then choose Insert > Insert Pie or…
- Pareto Chart in Excel: Use Word Labels and CountsYes—an Excel Pareto chart can use words such as “Late delivery” or “Damaged item” as category labels, with…
- Add a Bar Chart in Excel: Steps and TipsTo add a bar chart in Excel for Microsoft 365 on Windows, select the category labels and numeric…
- Excel Pivot Table Spill Error: Meaning, Causes and FixesIn Excel, a spill error is the standard #SPILL! error: a dynamic-array formula cannot put all of its…
- Pivot Table Report Is Invalid Error: Causes and FixesIn Excel, a “PivotTable report is invalid” message usually means the PivotTable’s source data or its field layout…
- Excel Chart Types: How to Choose the Right Chart for DataThere is no single best Excel chart type: choose the one that makes your data’s main message easiest…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.