Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Count Without Duplicates in Excel

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To count unique values in Excel, use =SUMPRODUCT(1/COUNTIF(range,range)) for a quick formula, or =COUNTA(UNIQUE(range)) if you have Microsoft 365. Both ignore duplicates and return the number of distinct entries. This guide walks through each method, explains when to use which, and covers the mistakes that make the formulas return errors or wrong totals.

What You'll Need

  • Excel 2013 or later for the SUMPRODUCT method; Microsoft 365 or Excel 2021 for the UNIQUE function.
  • A column of data with duplicates (names, order IDs, product codes — anything text or numeric).
  • Basic familiarity with entering formulas and selecting ranges.

Step-by-Step

  1. Identify your range. Suppose your data sits in A2:A100. Note the exact start and end rows. Do not include the header row in the range, or it will be counted as a unique value.
  2. Choose your method. If you have Microsoft 365 or Excel 2021, the UNIQUE function is simplest. For older versions, use SUMPRODUCT with COUNTIF.
  3. Method 1 — UNIQUE function (Microsoft 365 / Excel 2021). Click an empty cell, type =COUNTA(UNIQUE(A2:A100)), and press Enter. This spills the unique values and counts them. If you want the list itself, just enter =UNIQUE(A2:A100) in a cell with room below; the count is the number of rows that spill.
  4. Method 2 — SUMPRODUCT (all versions). In an empty cell, type =SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100)) and press Enter. This counts each distinct value once by dividing 1 by how many times each value appears, then summing.
  5. Method 3 — COUNTIF with a helper column (if you prefer visible steps). In B2, enter =COUNTIF($A$2:A2,A2) and fill down. This flags the first occurrence of each value with 1 and later duplicates with 2, 3, etc. Then count the 1s with =COUNTIF(B2:B100,1).
  6. Verify the result. Cross-check with a small sample: manually count unique entries in the first 10 rows and compare. If the formula returns a decimal or an error, see Troubleshooting.
  7. Handle blanks. The SUMPRODUCT/COUNTIF formula divides by zero if the range contains blank cells, producing #DIV/0!. Either restrict the range to cells with data or wrap with IFERROR: =SUMPRODUCT(IFERROR(1/COUNTIF(A2:A100,A2:A100),0)) entered as an array formula in older Excel (Ctrl+Shift+Enter). In Microsoft 365, IFERROR works without the special entry.
  8. Count duplicates only (optional). To count how many entries are duplicates (i.e., total rows minus unique count), use =COUNTA(A2:A100)-SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100)). This gives the number of extra occurrences beyond the first.

Common Mistakes

  • Including the header row. The header is treated as a unique value, inflating the count by one. Always start the range at the first data row.
  • Using whole-column references (A:A) with SUMPRODUCT. This can be very slow and may include blanks, causing #DIV/0!. Use a bounded range like A2:A1000.
  • Forgetting that COUNTIF is case-insensitive. "Apple" and "apple" are counted as the same value. If case matters, use SUMPRODUCT with EXACT: =SUMPRODUCT(--(COUNTIF(A2:A100,A2:A100)=1)) won't help; instead use =SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100)) still treats them same. For case-sensitive unique count, use =SUMPRODUCT((1/COUNTIF(A2:A100,A2:A100))*(MATCH(A2:A100,A2:A100,0)=ROW(A2:A100)-ROW(A2)+1)) — complex, so consider a helper column with EXACT.
  • Trailing spaces. "John " and "John" are different to Excel. Use TRIM in a helper column or clean data first.
  • Numbers stored as text. "123" and 123 may be counted separately. Use VALUE or clean via Text to Columns.

Tips

  • Use a dynamic named range or an Excel Table (Ctrl+T) so formulas auto-expand. With a table named Data, use .
  • To get a unique list sorted, use =SORT(UNIQUE(A2:A100)) in Microsoft 365.
  • For a quick visual check, apply Conditional Formatting > Highlight Cells Rules > Duplicate Values to see duplicates highlighted.
  • If you need to count unique values across multiple columns, combine them first with a helper column (e.g., =A2&"|"&B2) and then apply the unique count.
  • Remember that UNIQUE returns a spilled array; if you see #SPILL!, clear the cells below the formula.

Troubleshooting

  • #DIV/0! error: Usually caused by blank cells in the range. Restrict the range or use IFERROR as shown in step 7.
  • #NAME? error: UNIQUE is not available in your Excel version. Use the SUMPRODUCT method instead.
  • #SPILL! error: The formula's output is blocked by existing data. Select the formula cell and clear the cells below, or move the formula to an empty area.
  • Wrong count: Check for hidden rows, extra spaces, or inconsistent data types. Use TRIM and clean data. Also verify the range doesn't include unrelated columns.
  • Formula returns a decimal: This happens if the range includes cells that are not part of the data (e.g., text in a numeric column) causing COUNTIF to return 0 for some cells. Ensure the range is exactly the data.

Frequently Asked Questions

Can I count unique values with a pivot table?

Yes. Insert a pivot table, drag the field to the Rows area, then drag the same field to the Values area. In the Values field settings, choose "Distinct Count" (available in Excel 2013+ when using the Data Model). This gives a unique count without formulas.

What is the difference between unique and distinct?

Excel's UNIQUE function returns each different value once. "Distinct count" in a pivot table means the same: the number of different values. Some tools use "unique" to mean values that appear exactly once, but Excel's UNIQUE returns all different values regardless of frequency.

Does the SUMPRODUCT formula work with text and numbers mixed?

Yes, COUNTIF handles both. However, if the range contains errors (#N/A), the formula will return an error. Clean errors first or use IFERROR inside COUNTIF.

How do I count unique values in a filtered list?

Formulas like SUMPRODUCT/COUNTIF count all rows, including hidden ones. To count only visible rows, use =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")) with a helper column using SUBTOTAL, or use the pivot table approach on the filtered data.

Can I use UNIQUE on multiple columns?

Yes, UNIQUE can take a range like A2:B100 and returns unique rows. To count them, wrap with COUNTA: =COUNTA(UNIQUE(A2:B100)). This counts unique combinations of the two columns.

Why does my count include the header?

Because the range includes row 1. Adjust the range to start at row 2. If you use a table, reference the data body range only.