247Compliance appLinks, recordings and certificates
Open
Questions? Call +1-661-336-9555 Group training quotes Get the app
Software

Pivot Table Count Unique Values: Distinct Count in Excel

Count unique values in an Excel pivot table with the Data Model and Distinct Count, see why totals don’t add up, and use UNIQUE or legacy formulas on Mac, web and older Excel.

247 247Compliance · 15 min read

Key points

  • Distinct Count appears in Value Field Settings only when the PivotTable is built on the Data Model; Microsoft documents it for Excel for Windows (Microsoft 365, 2024, 2021, 2019 and 2016), and its summary list for Excel for the web does not include it.
  • A PivotTable’s Count works like COUNTA: it counts non-empty records, so one employee with three training records counts as three.
  • Distinct counts do not add up: in the sample log, 3 employees in October plus 4 in November is 7, but only 5 different employees trained.
  • Without the Data Model, =COUNTA(UNIQUE(range)) gives a distinct count in Microsoft 365, Excel 2024 and 2021 (Windows and Mac) and Excel for the web; a blank cell in the range adds one unless you filter blanks out.
  • On a Data Model PivotTable, Excel greys out the classic Calculated Field and Calculated Item commands; DAX measures, which Microsoft offers as another way to calculate, take their place.

To make a pivot table count unique values in Excel, tick Add this data to the Data Model when you insert the PivotTable, then change the value field from Count to Distinct Count. A normal PivotTable has no Distinct Count option, so it counts records: an employee with three training records counts three times. Below is a worked example you can rebuild in a few minutes, the reasons Distinct Count goes missing, and formulas that do the same job in Excel for Mac, Excel for the web and older versions.

Pivot table count unique values with the Data Model

Example (hypothetical): a compliance team logs every completed course and wants the number of different employees trained each month, not the number of completions. To follow along, type it into a blank sheet starting at cell A1 with the headers Date, Employee ID, Course and Month; the letters in brackets only show which column each one goes in, and column D is a formula added in step 1.

Date (A)Employee ID (B)Course (C)Month (D)
10/5/2026E101Harassment prevention2026-10
10/5/2026E102Harassment prevention2026-10
10/12/2026E101Data privacy2026-10
10/19/2026E103Data privacy2026-10
10/26/2026E102Data privacy2026-10
11/2/2026E101Anti-bribery2026-11
11/9/2026E104Harassment prevention2026-11
11/9/2026E104Data privacy2026-11
11/16/2026E105Anti-bribery2026-11
11/23/2026E102Anti-bribery2026-11

The log has 10 records for 5 different employees: 5 records and 3 employees in October, 5 records and 4 employees in November.

Step 1: Make the data a table and add a Month column

Click any cell in the data and press Ctrl+T (Insert > Table), keeping My table has headers ticked. In D2 enter =TEXT(A2,"yyyy-mm"); inside a table, Excel fills the formula down the column. A table also picks up new rows when you refresh the PivotTable, which Microsoft recommends for PivotTable sources.

Step 2: Insert the PivotTable and add it to the Data Model

  1. Select a cell in the table and choose Insert > PivotTable.
  2. Choose New Worksheet.
  3. Tick Add this data to the Data Model, then select OK.

Without this check box, Distinct Count does not appear later. If an older report was built without it, the simplest fix is to insert a new PivotTable from the same table with the box ticked.

Step 3: Change Count to Distinct Count

Drag Month to Rows and Employee ID to Values. Because the IDs are text, Excel shows Count of Employee ID: 5, 5 and 10. Right-click any of those numbers, choose Value Field Settings, open the Summarize Values By tab, select Distinct Count and select OK. Microsoft’s summary function reference describes it as “The number of unique values” and notes that it “only works when you use the Data Model in Excel.” You can also reach the dialog from the PivotTable Analyze tab (Analyze in some older versions): Active Field > Field Settings.

MonthCount of Employee IDDistinct Count of Employee ID
2026-1053
2026-1154
Grand Total105

Can you group dates by month instead of using a helper column?

Yes. In a normal PivotTable, right-click a date, choose Group and pick Months (and Years if the data spans more than one year), as shown in Microsoft’s guide to grouping PivotTable data. In a Data Model PivotTable, dragging the Date field to Rows can make Excel add Date (Year), Date (Quarter) and Date (Month) fields automatically, a feature Microsoft introduced in Excel 2016. The helper column is used here because the same 2026-10 label then works in the PivotTable and in the formulas further down.

Pivot table distinct count vs Count: why the totals don’t add up

Count and Distinct Count answer different questions. Microsoft’s PivotTable calculation guide says the Count summary “works the same as the COUNTA function”: it counts every non-empty entry, so it tells you how many courses were completed. Distinct Count tells you how many different people completed them.

Distinct counts are not additive. October’s 3 employees plus November’s 4 makes 7, yet the grand total is 5, because E101 and E102 trained in both months. Microsoft’s DISTINCTCOUNT reference explains the same behavior: each value is counted once at every level of the report. Do not replace the grand total with a sum of the rows. If someone asks for 7, they are asking for “employee-months”, which is a different measure and should be labeled as one.

Blank and inconsistent IDs

Distinct Count in a Data Model PivotTable is an implicit measure built on DISTINCTCOUNT, and Microsoft’s DAX reference says DISTINCTCOUNT counts the BLANK value. A record with no employee ID therefore adds one to its month’s count (and appears as a (blank) item if you put Employee ID in Rows). Fill in or remove those records, or create an explicit measure that skips blanks: choose Power Pivot > Calculations > Measures > New Measure, enabling the Power Pivot add-in first if the tab is missing (Microsoft’s measure instructions) and enter =DISTINCTCOUNTNOBLANK(Table1[Employee ID]), using your table’s name from the Table Design tab. Select Check Formula before OK; if your Excel version does not recognize the function, it will say so.

Distinct Count compares the stored values, not what you meant to type. An ID entered as E101 in one row and E-101 in another counts as two people, so clean the ID column before you trust the number.

Why is Distinct Count missing from Value Field Settings?

If Distinct Count is not in the Summarize Values By list, check these causes in order:

  • The PivotTable is not on the Data Model. Insert a new PivotTable with Add this data to the Data Model ticked.
  • You are in Excel for the web. Microsoft’s list of summary functions for PivotTables in Excel for the web runs from Sum to Varp and does not include Distinct Count.
  • You are in Excel for Mac. Microsoft’s Distinct Count, Data Model and Power Pivot pages do not list Excel for Mac, and the Add this data to the Data Model step appears only in its Windows instructions for creating a PivotTable.
  • The source is an OLAP cube. Microsoft says you cannot change the summary function for fields from OLAP source data; the calculations are set on the server.
Excel version (as Microsoft documents it, November 2026)Distinct Count in a PivotTableUNIQUE functionBest route
Excel for Microsoft 365, Excel 2024, Excel 2021 (Windows)Yes, with the Data ModelYesEither
Excel 2019, Excel 2016 (Windows)Yes, with the Data ModelNot listedPivotTable, or the legacy formula below
Excel for Microsoft 365 for Mac, Excel 2024 for Mac, Excel 2021 for MacNot listed by MicrosoftYesUNIQUE formula or helper column
Excel for the webNot in Microsoft’s summary function list for the webYesUNIQUE formula or helper column

Calculated Field greyed out after you add the Data Model

The trade-off: on a Data Model PivotTable, Excel greys out Fields, Items, & Sets > Calculated Field and Calculated Item. Microsoft’s calculation guide does not name the Data Model here; it says formulas cannot be created in PivotTables connected to OLAP data, and it offers measures in Power Pivot, written in the DAX formula language, as another way to calculate. If an existing report depends on calculated fields, rebuild them as measures before you switch, or keep the normal PivotTable and use the helper column method below. The recorded Excel Power Pivot data modeling webinar covers table relationships, DAX basics and measures such as year to date.

Count unique values in Excel with a formula

Formulas give a distinct count outside a PivotTable and work where the Data Model does not. All results below use the sample data in A1:D11.

Count unique values in a column with COUNTA and UNIQUE

=COUNTA(UNIQUE(B2:B11)) returns 5. UNIQUE returns the list of distinct IDs and COUNTA counts them. Microsoft lists UNIQUE for Excel for Microsoft 365 (Windows and Mac), Excel 2024, Excel 2021 (Windows and Mac) and Excel for the web, but not Excel 2019 or 2016.

A blank cell in the range adds one to that result, because UNIQUE returns the blank as one more item. If the column can contain blanks, use =IFERROR(ROWS(UNIQUE(FILTER(B2:B11,B2:B11<>""))),0), which also returns 5 here. FILTER drops the empty cells; if nothing is left, FILTER returns #CALC!, which COUNTA would count as 1, so ROWS with IFERROR returns 0 instead.

Distinct count with criteria: one month or one course

Add the condition inside FILTER. =COUNTA(UNIQUE(FILTER(B2:B11,D2:D11="2026-10"))) returns 3, and the same formula with "2026-11" returns 4. To count employees who completed Data privacy, use =COUNTA(UNIQUE(FILTER(B2:B11,C2:C11="Data privacy"))), which returns 4. If a month or course has no records, these formulas return 1, not 0, because COUNTA counts the #CALC! error; use the IFERROR(ROWS(UNIQUE(FILTER(…))),0) form above when that can happen.

One formula for every month: GROUPBY

In Excel for Microsoft 365, GROUPBY builds the whole summary in one formula. Its function argument accepts a LAMBDA, so =GROUPBY(D2:D11,B2:B11,LAMBDA(x,ROWS(UNIQUE(x))),0,0) spills two rows: 2026-10 with 3 and 2026-11 with 4. The fourth argument (0) says the ranges have no headers and the fifth (0) turns off totals, which avoids any confusion with the non-additive grand total. Microsoft lists GROUPBY for Excel for Microsoft 365 only.

Excel 2019 and 2016: the legacy array formula

Without UNIQUE, use the IF, SUM, FREQUENCY, MATCH and LEN combination from Microsoft’s count unique values among duplicates article:

=SUM(IF(FREQUENCY(IF(LEN(B2:B11)>0,MATCH(B2:B11,B2:B11,0),""),IF(LEN(B2:B11)>0,MATCH(B2:B11,B2:B11,0),""))>0,1))

It returns 5. In versions without dynamic arrays, confirm it with Ctrl+Shift+Enter so Excel adds the curly brackets. MATCH gives each ID the position of its first appearance (1, 2, 1, 4, 2, 1, 7, 7, 9, 2), FREQUENCY counts each first position once and returns zero for repeats, LEN keeps blank cells out, and SUM(IF(…>0,1)) counts the positions that remain.

Excel pivot count unique without the Data Model

In Excel for Mac or Excel for the web, a helper column lets a normal PivotTable produce the same monthly numbers. In E1 type First in month, in E2 enter =IF(COUNTIFS(B$2:B2,B2,D$2:D2,D2)=1,1,0) and fill down. Each row gets 1 the first time an employee appears in a month and 0 after that: 1, 1, 0, 1, 0, 1, 1, 0, 1, 1.

Build a normal PivotTable with Month in Rows and Sum of First in month in Values. It shows 3 for 2026-10 and 4 for 2026-11, but its grand total is 7, not 5, because the flag marks the first record per employee per month. The helper column is only right for the grouping it was built for: if you filter or slice by course, or need a different breakdown, build a flag that includes that column, and take the overall total from COUNTA(UNIQUE()).

Which unique count method should you use?

Flowchart for choosing a unique count method in Excel: if the count must be in a PivotTable, use the Data Model and Distinct Count on Excel for Windows, or a helper column with Sum on Mac or the web; otherwise use COUNTA with UNIQUE where available, or the legacy FREQUENCY array formula in Excel 2019 and 2016. Footer: 3 in October plus 4 in November is 7, but only 5 different employees.
Pick the method your Excel version supports, then check the grand total: a distinct count total is not the sum of its rows. Tap the image to open it full size.
MethodWhere it worksSample resultWatch for
Data Model PivotTable, Distinct CountExcel for Windows3, 4, total 5No classic calculated fields; blank IDs count as one
=COUNTA(UNIQUE(range))Microsoft 365, 2024, 2021 (Windows and Mac), web5Blank cells add one; use the FILTER version
FILTER inside UNIQUE for criteriaSame as UNIQUE3 (October), 4 (Data privacy)Exact text match on the criterion
GROUPBY with LAMBDAMicrosoft 3653 and 4Not in perpetual versions
Helper column in a normal PivotTableAll versions, including Mac and web3, 4, total 7Grand total and other breakdowns are wrong
Legacy FREQUENCY array formulaAll versions5Ctrl+Shift+Enter in older Excel

For a one-off list rather than a live count, the same Microsoft article describes Data > Advanced with Unique records only to copy the distinct values elsewhere, then ROWS to count them. The copy does not update when the log changes.

If the IDs come from a separate HR roster, match them first with a lookup; XLOOKUP vs VLOOKUP explains which function to use. And if the count goes into an audit file, the log behind it matters as much as the formula.

What to do now

  • Check your Excel version (File > Account > About Excel on Windows) against the version table above.
  • Turn the source data into an Excel table and clean the ID column: no blanks, one spelling per person.
  • On Windows, insert a new PivotTable with Add this data to the Data Model ticked and switch the ID field to Distinct Count.
  • Check the result against =COUNTA(UNIQUE()) on the same column, and never sum distinct counts to get a total.
  • Before you switch an existing report to the Data Model, list its calculated fields and plan the DAX measures that will replace them.
  • On Mac or the web, use the UNIQUE formulas or the helper column and label what the grand total means.

More Excel sessions are listed under Software webinars, and new live dates appear in the 247Compliance newsletter.

Frequently asked questions

How do I count unique values in an Excel pivot table?

In Excel for Windows, insert the PivotTable with Add this data to the Data Model ticked, put the field to count in Values, then open Value Field Settings and choose Distinct Count on the Summarize Values By tab. A PivotTable created without the Data Model does not offer Distinct Count, so insert a new one with the box ticked.

Why is Distinct Count not showing in my pivot table?

The usual reason is that the PivotTable was created without Add this data to the Data Model. Microsoft’s list of PivotTable summary functions for Excel for the web does not include Distinct Count, and its Data Model pages do not list Excel for Mac, so on a Mac or the web use COUNTA with UNIQUE or a helper column. Fields from an OLAP cube also do not let you change the summary function.

Why doesn’t the distinct count grand total equal the sum of the rows?

Because a person who appears in more than one row is counted once in each row but only once in the total. Microsoft’s DAX documentation describes distinct count totals as not additive. If you need the sum of the rows, label it as a different measure, such as employee-months.

How do I count unique values in Excel without a pivot table?

Use =COUNTA(UNIQUE(range)) in Excel for Microsoft 365, Excel 2024, Excel 2021 or Excel for the web; if the range can contain blanks, filter them out first with FILTER, because a blank adds one to the result. In Excel 2019 or 2016, which do not have UNIQUE, use Microsoft’s SUM, IF, FREQUENCY, MATCH and LEN array formula, confirmed with Ctrl+Shift+Enter.

Does pivot table Distinct Count include blank cells?

Yes. Distinct Count in a Data Model PivotTable uses DISTINCTCOUNT, which Microsoft’s DAX reference says counts the BLANK value, so a missing ID adds one to the count. Fix the source records, or create a measure with DISTINCTCOUNTNOBLANK if your Excel version accepts it.

Can I add a calculated field to a Data Model pivot table?

Not with the classic Calculated Field command, which Excel greys out on Data Model PivotTables. Use a measure written in DAX instead, created from Power Pivot > Calculations > Measures > New Measure (enable the Power Pivot add-in if the tab is missing). If you need classic calculated fields, keep a normal PivotTable and use a helper column or formula for the unique count.

Build PivotTable reports that answer at a glance

Excel MVP David Benaim’s live webinar on Wednesday, December 16, 2026 (10:00 AM PT) shows how to aggregate data with PivotTables and the GROUPBY function, add slicers and timelines, and pick the right chart for each question.

See the Excel dashboards webinar
Sources (19)
  1. Microsoft Support: Change the summary function or custom calculation for a field in a PivotTable (Distinct Count, Data Model requirement, OLAP restriction)
  2. Microsoft Support: Create a PivotTable to analyze worksheet data (Windows, web and Mac instructions; Add this data to the Data Model)
  3. Microsoft Support: Calculate values in a PivotTable (Count works like COUNTA; summary functions for Excel for the web; OLAP limits on formulas; calculated fields)
  4. Microsoft Support: Group or ungroup data in a PivotTable
  5. Microsoft Support: Create a Data Model in Excel (Applies To list)
  6. Microsoft Support: Power Pivot - overview and learning (the old “Where is Power Pivot?” link now redirects here; Applies To list; enabling the add-in)
  7. Microsoft Support: Measures in Power Pivot (implicit measures: SUM, COUNT, MIN, MAX, DISTINCTCOUNT, AVG)
  8. Microsoft Support: Create a Measure in Power Pivot (Measures > New Measure, Check Formula)
  9. Microsoft Learn: DISTINCTCOUNT function (DAX) (counts BLANK; totals not additive)
  10. Microsoft Learn: DISTINCTCOUNTNOBLANK function (DAX)
  11. Microsoft Support: UNIQUE function (syntax and Applies To list)
  12. Microsoft Support: FILTER function (#CALC! when no results, if_empty argument)
  13. Microsoft Support: COUNTA function (counts error values and empty text)
  14. Microsoft Support: ROWS function
  15. Microsoft Support: GROUPBY function (function argument accepts a lambda; Applies To Excel for Microsoft 365)
  16. Microsoft Support: Count unique values among duplicates (IF, SUM, FREQUENCY, MATCH, LEN; Advanced Filter Unique records only)
  17. Microsoft 365 blog: Time grouping enhancements in Excel 2016 (October 13, 2015)
  18. 247Compliance: Interactive dashboards & analytics in Excel (live webinar, December 16, 2026)
  19. 247Compliance: Data Modelling and Analysis with Excel Power Pivot (recorded webinar)

This article is general information, not legal or tax advice. Check the official sources above or consult a qualified advisor for your situation.

How we research, check and correct articles: editorial policy. Spotted an error? Tell us.

LIVE WEBINAR · 10 DEC · 10:00 AM PT · 1:00 PM ET Enhancing Pivot Tables with Images: Visualize Your Data Like a Pro Abdelrahman Abdou · 60 min · from $179 Enroll
Share