Count unique values in Excel with a formula built on SUMPRODUCT and COUNTIF, and you get the number of distinct entries in a range; count distinct entries that appear at least once and you get that number too, but only the modern dynamic-array approach or a pivot table handles blanks and case differences predictably. The right pick depends on your Excel version and whether the range holds text, numbers, or mixed data. Every method below names the exact function, the range syntax, and the result you should expect.
The five working methods covered here are the legacy SUMPRODUCT/COUNTIF formula, the modern UNIQUE function on Microsoft 365, the COUNTA/COUNTIF combination for sibling columns, the pivot-table route for a no-formula count, and the conditional-formatting trick for visually flagging duplicates. Each has a version boundary, and most failures trace to one of four causes: blank cells, case sensitivity, trailing spaces, or a range with mixed types.
The SUMPRODUCT-COUNTIF Formula That Works in Every Excel Version
The legacy formula =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")) returns the count of distinct non-blank entries in A2:A100 and runs unchanged from Excel 2007 forward, including Excel for Mac 2011 onward. The double-counting fix is the division: each value gets a fraction equal to one divided by its total occurrence count, and SUMPRODUCT adds the fractions back to whole numbers.
Take a range holding Apple, Banana, Apple, Cherry. COUNTIF returns 2, 1, 2, 1 for the four rows. The division produces 1/2, 1, 1/2, 1, and the sum is 3. That is the count of distinct values: Apple, Banana, Cherry. The formula does not deduplicate the list, it only reports how many distinct entries exist.
The &"" tail matters. Without it, COUNTIF silently treats blank cells as zero and stops counting them, which throws off the fractions in ranges with gaps. The (A2:A100<>"") test excludes blanks from the numerator so they don't inflate the total. Both pieces belong in the formula; dropping either one produces a wrong count on real-world data.
Microsoft's documentation for COUNTIF states that it accepts up to 255 range arguments and that text matching is case-insensitive by default. That default is why Apple and apple get counted once β which is often what you want, but rarely what a database manager wants. If case matters, the formula needs an array with EXACT instead, and that returns a different number.
The UNIQUE Function: What It Returns on Microsoft 365 and Excel 2021
=COUNTA(UNIQUE(A2:A100)) returns the same distinct count on Excel 2021 and Microsoft 365, and it is the shortest formula in the list. UNIQUE is a dynamic-array function released with Microsoft 365 in 2019 and included in the perpetual Excel 2021 release; it does not exist in Excel 2019 or earlier, and typing it there returns #NAME?. Microsoft's UNIQUE documentation states the function returns a list of unique values from a range or array and that the exactly_once argument, set to TRUE, returns only values that appear exactly once.
The distinction matters because "unique" in common usage splits two ways. Count distinct entries and Apple in a list with Apple twice still counts once. Count values that appear exactly once and Apple drops out entirely. =COUNTA(UNIQUE(A2:A100,,TRUE)) gives the second answer β the count of values appearing exactly one time. If your reader means "how many values occur only once," the legacy formula cannot deliver that cleanly; UNIQUE with the third argument can.
UNIQUE handles blanks differently from the legacy formula. On a range with trailing empty cells, UNIQUE(A2:A100) returns a 0 in the output when the range includes blanks, and COUNTA counts that zero as an entry. Wrap it: =COUNTA(UNIQUE(FILTER(A2:A100,A2:A100<>""))). The FILTER step, also a Microsoft 365 function, removes blanks before UNIQUE sees them. FILTER arrived in the same release wave as UNIQUE, so versions align.
Case sensitivity flips here too. UNIQUE treats Apple and apple as distinct, because Excel's comparison engine runs case-insensitive for COUNTIF but case-sensitive for array comparisons in modern functions. A list with Apple, apple, and Banana returns 3 from UNIQUE and 2 from the SUMPRODUCT/COUNTIF formula. Neither is wrong; they answer different questions, and knowing which you asked is half the battle.
| Method | Formula | Excel versions | Blanks handled | Case sensitivity |
|---|---|---|---|---|
| SUMPRODUCT/COUNTIF | =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")) | 2007 onward | Yes, with <>"" test | Case-insensitive |
| UNIQUE + COUNTA | =COUNTA(UNIQUE(A2:A100)) | 2021, Microsoft 365 | No β needs FILTER wrapper | Case-sensitive |
| Pivot table | Rows field, then Count | All versions | Excludes blanks from count | Case-insensitive |
| Conditional formatting | Highlight duplicates | All versions | Ignores blanks | Case-insensitive |
Counting Unique Values Across Two Columns Without a Helper Column
A single-column formula answers the single-column question. Real sheets usually hold first names in column A and last names in column B and want the number of distinct full-name combinations. The array formula =SUM(1/COUNTIFS(A2:A100,A2:A100,B2:B100,B2:B100)) entered as an array returns that count on pre-365 versions, and =COUNTA(UNIQUE(A2:A100&"|"&B2:B100)) returns it on Microsoft 365.
The COUNTIFS variant divides each row's contribution by the number of rows sharing the same first-and-last pair, so duplicate pairs collapse. Two rows of John Smith contribute 1/2 each and sum to 1. A pair with a blank in column B still counts, which may or may not be what you want; adding (A2:A100<>"")*(B2:B100<>"") as a multiplier drops both-blank rows.
The concatenation route is cleaner on 365 but risks collisions. If the delimiter could appear inside a value β a pipe in a product name, for example β two different pairs can produce the same concatenated string. Use CHAR(1), the non-printing Start of Heading character, as a delimiter: =COUNTA(UNIQUE(A2:A100&CHAR(1)&B2:B100)). The character will not appear in ordinary text.
For a three-column answer, extend the pattern. COUNTIFS takes additional criteria ranges in pairs, up to 127 pairs per Microsoft's documentation; the concatenation route adds another &CHAR(1)& segment per column. Beyond about five columns the formula gets unwieldy and a pivot table with all columns in the Rows area does the job with no syntax to break.
Pivot Tables and the Distinct Count That Hides in the Field Settings
A pivot table counts distinct values without a formula, and the route is non-obvious enough that most users miss it. Drag the field into the Values area, then right-click the value field, choose Value Field Settings, scroll to the bottom of the function list, and select Distinct Count. The option sits below the standard eleven functions and is present in Excel 2013 and later, and only when the pivot table's data source is the Excel Data Model β a check-box labeled "Add this data to the Data Model" at pivot table creation.
Without the Data Model, Distinct Count does not appear in the list. This is the single most common reason people report the feature as missing on Excel 2016 or 2019. Rebuild the pivot table through Insert > PivotTable and tick the Data Model box, and the option returns.
The pivot table route is the only one on this page that outputs a summary table alongside the count. Group the data by region, add the customer names field to the Values area as Distinct Count, and you get the distinct customers per region in the same view. That combination β grouping plus distinct count β is what makes pivot tables worth the extra clicks over a formula. A formula can count distinct across a whole range, not per group, without nesting SUMPRODUCT inside IF.
Blanks are excluded from the Distinct Count automatically. Pivot tables ignore empty cells in the Values area by default, so a range with gaps yields the count of distinct non-blank values without any FILTER wrapper. That is one of the few places where the pivot table beats every formula, and a reason to reach for it on dirty data.
Why the Count Comes Out Wrong: Blanks, Spaces, Case, and Mixed Types
A unique count that looks too high usually has trailing spaces. "Apple" in one cell and "Apple " with a trailing space in another are different strings to every formula in Excel, including COUNTIF, though COUNTIF's text comparison may still fold them together depending on the range size and collation. The reliable fix is a cleanup pass: select the column, run Data > Text to Columns with the Delimited option and no delimiter, which trims leading and trailing spaces from text values, or wrap the range in TRIM inside the array formula.
A count that looks too low usually has numbers stored as text. The string "001" and the number 1 render identically in a cell that formats as text but are different values to COUNTIF when one is stored as text and the other as a number. On Microsoft 365, ISNUMBER reveals which rows are text; on legacy versions, the error-checking triangle in the corner of the cell flags the same problem. Convert the column with Data > Text to Columns, or multiply by 1 in a helper column, and re-run the count.
Case sensitivity splits the answer. COUNTIF is case-insensitive as documented, UNIQUE is case-sensitive, and a pivot table follows COUNTIF's behavior. If a list holds "New York," "new york," and "NEW YORK" as three rows, the legacy formula returns 1 and UNIQUE returns 3. Neither is a bug; the case difference is invisible unless you know which engine you are using, and deciding on a canonical case before counting is the practical fix.
Mixed types are the fourth trap. A range holding dates stored as text alongside real dates, or numbers stored as text alongside numbers, produces counts that depend on which engine sees which row. On Microsoft 365, =COUNTA(UNIQUE(A2:A100)) treats the text "10" and the number 10 as one entry only if the range's cell formatting coerces them together, which it often does not. Convert everything to one type first, using ISTEXT and ISNUMBER as a diagnostic filter.
The Quick Check: Conditional Formatting to See Duplicates Before You Count Them
Conditional formatting cannot count unique values, but it flags duplicates before you ask for a number, and that saves the common failure where you count first and discover a dirty range second. Select the range, choose Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values, and Excel shades repeated entries in one color. The Duplicate Values dialog also has a Unique option, which shades values that appear exactly once β a visual equivalent of the exactly-once count.
The setting operates on the displayed value, so "Apple" and "Apple " may be flagged as distinct even when COUNTIF folds them. It also ignores blanks by default. A range with three duplicate sales totals and two identical customer names can be checked visually in a second, and the color fills vanish the moment the rule is cleared, so it does not alter data.
For a permanent color audit, use a formula rule: Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, with =COUNTIF($A$2:$A$2,A2)>1 to flag the first appearance of any repeated value. The mixed-anchor range $A$2:$A$2 grows as the rule copies down, which highlights the row where a value first repeats rather than every occurrence β the visual counterpart to the "exactly once" question.
Combining the Count With SUMIFS and FILTER for a Conditional Unique Total
The unique count rarely earns its keep on its own; it tags along with a filter. =SUMPRODUCT((B2:B100="East")/COUNTIFS(A2:A100,A2:A100,B2:B100,B2:B100)) returns the number of distinct customers with sales in the East region, though the division by COUNTIFS produces division-by-zero errors for rows outside the filter, which multiply against FALSE and vanish β a well-known behavior, but one that returns #DIV/0! if the entire range fails the filter.
On Microsoft 365, =COUNTA(UNIQUE(FILTER(A2:A100,B2:B100="East"))) returns the same number cleanly, with an empty-result error if no rows match. Wrap with IFERROR to display 0: =IFERROR(COUNTA(UNIQUE(FILTER(A2:A100,B2:B100="East"))),0). The FILTER function's include argument accepts a boolean array, and nesting multiple conditions uses multiplication: (B2:B100="East")*(C2:C100>100) requires both.
The pattern extends to SUMIFS paired with the unique count. A dashboard that needs both "how many distinct customers bought in the East" and "what did they spend" pairs the count formula with =SUMIFS(D2:D100,B2:B100,"East"), and the two line up because both operate on the same source range. Mixing ranges β counting from A, summing from D β introduces the classic pivot-vs-formula disagreement when rows are sorted differently; keep both ranges aligned to the same row set.
A Worked Cost Example: Distinct Price Points Against a Rounded Total
Suppose a purchase ledger holds 12,000 transactions in A2:A12001, unit prices in B2:B12001 to two decimal places, and a total-spend figure in C2:C12001. The finance team wants the number of distinct price points, because the negotiated contract sets price by SKU and rounded prices on a report imply a rounding error in the source system.
=SUMPRODUCT((B2:B12001<>"")/COUNTIF(B2:B12001,B2:B12001&"")) returns the distinct price count. On a clean sample of the ledger, the formula returns 47 distinct prices across 12,000 rows, but the contract names 52 SKUs. That gap of five is the trigger for investigation, not a rounding issue β five SKUs are missing prices or three are mis-typed. The count does the work of narrowing the question; the pivot table with price in Rows and count in Values hands over the exact five missing values.
Run the same check on the modern engine. =COUNTA(UNIQUE(B2:B12001)) returns the same 47 on this data, unless some prices are stored as text β a common export artifact when the ledger comes from a system that writes currency with a symbol. Re-run after converting the column, and if the number changes, the text-formatting issue explains the missing SKUs rather than a genuine gap. The two engines agreeing is the clean result; a disagreement points to the data.
Where Running the Count Every Time Costs You: Macros and Cached Results
For a monthly report that re-runs the count on the same workbook, the formula recalculates every time any cell changes. On a 12,000-row sheet the legacy SUMPRODUCT/COUNTIF takes a measurable fraction of a second, and it recalculates on every edit. On the modern engine, COUNTA(UNIQUE(...)) uses the same recalculation cycle, and a stacked set of dynamic arrays can slow a large workbook noticeably. Both behave differently from a static pivot table, which caches its result and only re-queries when refreshed.
The practical rule: report on a static export, paste values from the formula once and re-run only when the source changes. For a live dashboard that needs the count to update, the pivot table refreshes on demand (right-click > Refresh) rather than automatically, which is the quiet advantage warehouses and analysts rely on. A macro that runs the count on Workbook_Open adds a startup delay of the recalc time on every open, which on a heavy workbook is the reason a saved static number is worth the paste.
Use the legacy formula when the workbook must open in Excel 2016 or older. Use UNIQUE when the version supports it and the intent is clear β distinct count versus exactly-once. Use a pivot table when the answer must be grouped or needs to survive sort and filter changes. Each is right for one question, and mixing them is the source of most "my count is wrong" reports.
FAQ
Does COUNTIF count blanks as unique values?
No. COUNTIF treats a blank cell as a zero-length string when the criteria is empty text, but the &"" tail in the standard formula converts the comparison so that empty cells do not increment their own denominator. The (A2:A100<>"") test excludes blanks from the numerator, so a range holding ten entries and five blanks returns ten, not five or fifteen. If your count includes blanks, the formula has been altered.
What is the difference between count distinct and count unique in Excel?
Count distinct returns the number of different values β Apple, Banana, and Apple again count as two distinct entries. Count unique returns the number of values appearing exactly once β in that same list, Banana counts as one unique value and Apple does not count at all, because it appears twice. Microsoft's UNIQUE documentation distinguishes the two with the exactly_once argument, while the legacy formula answers only the first question.
Why does UNIQUE return #NAME? on my Excel 2019?
UNIQUE does not exist in Excel 2019 or earlier; it was released with Microsoft 365 and included in Excel 2021. The #NAME? error confirms the function is unrecognized, not that it is misspelled. Use the SUMPRODUCT/COUNTIF formula on those versions, or open the file in a Microsoft 365 build and save the result as a static value before sending it to a colleague on Excel 2019.
Can I count unique values by group without a pivot table?
Yes, with an array formula on Microsoft 365: =COUNTA(UNIQUE(FILTER(A2:A100,B2:B100="East"))) returns distinct customers in the East group. On older versions, nest COUNTIFS inside SUMPRODUCT: =SUMPRODUCT((B2:B100="East")/COUNTIFS(A2:A100,A2:A100,B2:B100,B2:B100)). Both formulas return one number per group; neither builds the per-group summary table a pivot table produces in one drag.
Does a pivot table's distinct count include blanks?
No. Pivot tables exclude empty cells from the Distinct Count function automatically, so a range with gaps returns the count of distinct non-blank values with no cleanup formula. That differs from COUNTA(UNIQUE(...)), which counts a zero from blank rows unless wrapped in FILTER. If you see a distinct count that matches your expectation without any data cleanup, the pivot table is the likely cause.