Smart Systems for Home

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

Excel COUNTIF Without Duplicates: Unique Count Guide

· 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 values in Excel while ignoring duplicates, use a formula that divides 1 by a COUNTIF of each item and sums the results: =SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10)). This returns the number of distinct entries in the range. If you only want to count how many times a specific value appears once (not total occurrences), use =SUMPRODUCT((A2:A10="apple")/COUNTIF(A2:A10,A2:A10)). Both formulas work in Excel for Microsoft 365, Excel 2021, 2019, and 2016. No add-ins are required. The only prerequisite is that your range contains no blank cells, because COUNTIF returns 0 for blanks and division by zero produces an error.

What You'll Need

  • Excel 2016 or later (desktop) or Excel for Microsoft 365. The formulas also work in Excel for the web, though array entry differs slightly.
  • A column of data with no blank cells inside the range you reference.
  • Basic familiarity with selecting a cell and typing a formula.

Step-by-Step

  1. Prepare your data. Put the values you want to count in a single column, for example A2:A10. Remove or fill any blank cells inside that range. If blanks are unavoidable, use the variant in the Tips section that ignores empty cells.
  2. Select an empty cell where the result should appear, such as C1.
  3. Type the distinct-count formula: =SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10)). Replace A2:A10 with your actual range. Press Enter. The result is the number of unique values, not the total number of rows.
  4. Check the logic. For each cell, COUNTIF returns how many times that value appears. Dividing 1 by that count gives a fraction; SUMPRODUCT adds the fractions. A value appearing three times contributes 1/3 three times, totalling 1. So each distinct value counts once.
  5. Count a specific value once. If you want to know whether "apple" appears at all (1 if present, 0 if not), use =SUMPRODUCT((A2:A10="apple")/COUNTIF(A2:A10,A2:A10)). This counts the value once regardless of how many times it repeats.
  6. Use a dynamic range if data grows. Convert the range to an Excel Table (select the data, press Ctrl+T) and reference the column, e.g. =SUMPRODUCT(1/COUNTIF(Table1[Item],Table1[Item])). The formula then expands automatically as rows are added.
  7. Verify the result by using Data > Remove Duplicates on a copy of the column and comparing the remaining row count. Do this on a duplicate sheet, not your original, because Remove Duplicates permanently deletes rows.

Common Mistakes

  • Blank cells in the range. COUNTIF returns 0 for an empty cell, and 1/0 produces #DIV/0!. Fill blanks or use the IF-based variant below.
  • Using COUNTIF alone. COUNTIF counts all occurrences, not distinct values. You need the SUMPRODUCT wrapper.
  • Forgetting absolute references when copying. If you copy the formula down, the range shifts unless you lock it with $ signs, e.g. $A$2:$A$10.
  • Case sensitivity. COUNTIF is not case-sensitive, so "Apple" and "apple" count as one distinct value. Use SUMPRODUCT with EXACT if case matters.
  • Trailing spaces. "apple " and "apple" are treated as different values. Clean data with TRIM first.
  • Entering as a normal formula in older Excel. The SUMPRODUCT version does not need Ctrl+Shift+Enter, but if you rewrite it with SUM instead, older versions require array entry.

Tips

  • To ignore blanks, use =SUMPRODUCT((A2:A10<>"")/COUNTIF(A2:A10,A2:A10&"")). The concatenation with an empty string prevents division by zero.
  • For case-sensitive distinct counts, use =SUMPRODUCT(--(FREQUENCY(IF(EXACT(A2:A10,TRANSPOSE(A2:A10)),MATCH(ROW(A2:A10),ROW(A2:A10))),ROW(A2:A10))>0)) entered as an array formula in older versions. This is complex; only use it when case truly matters.
  • If you have Excel for Microsoft 365, =COUNTA(UNIQUE(A2:A10)) is simpler and handles blanks if you filter them: =COUNTA(UNIQUE(FILTER(A2:A10,A2:A10<>""))). UNIQUE is not available in Excel 2019 or earlier.
  • Name your range (Formulas > Define Name) to make formulas easier to read and maintain.
  • Keep a helper column with =COUNTIF($A$2:$A$10,A2) if you want to see occurrence counts alongside the distinct total.

Troubleshooting

  • #DIV/0! error: A blank or empty-text cell exists in the range. Use the blank-safe formula above or fill the gaps.
  • Result is higher than expected: Check for trailing spaces, inconsistent capitalisation, or numbers stored as text. Use TRIM and VALUE to clean.
  • Result is lower than expected: COUNTIF treats some text and numbers as equal (e.g. "1" and 1). Ensure data types are consistent.
  • Formula returns 0: Confirm the range reference is correct and that the lookup value in the specific-value version matches exactly, including spaces.
  • Formula is slow on large ranges: COUNTIF inside SUMPRODUCT is quadratic. For tens of thousands of rows, use a pivot table or the UNIQUE function in Microsoft 365.
  • If that did not work: Rebuild the formula in a clean cell, type the range manually rather than clicking, and press Enter once. Then test on a small sample of five rows to confirm the logic before applying it to the full column.

Frequently Asked Questions

What is the difference between COUNTIF and counting unique values?

COUNTIF counts every occurrence of a criterion. Counting unique values counts each distinct entry once, regardless of how many times it appears. The SUMPRODUCT/COUNTIF combination converts occurrence counts into distinct counts.

Can I count unique values across two columns?

Yes, but it is more complex. Combine the columns into one helper range first (e.g. using CHOOSE or by stacking), then apply the same formula. Simpler: copy both columns into one column on a helper sheet and run the formula there.

Does the formula work in Excel for the web?

SUMPRODUCT and COUNTIF work in Excel for the web. The UNIQUE function also works there for Microsoft 365 subscribers. Array-entry shortcuts differ, but the SUMPRODUCT version needs no special entry.

Why does my formula count "Apple" and "apple" as one value?

COUNTIF is case-insensitive by design. If case matters, you need an EXACT-based array formula or a helper column using EXACT, then count distinct values on that helper column.

Can I use this with a filtered list?

SUMPRODUCT/COUNTIF does not respect filters; it evaluates all rows in the range. To count distinct visible values only, use SUBTOTAL with OFFSET inside SUMPRODUCT, which is significantly more complex. A pivot table is usually the cleaner choice.

What if my range contains errors like #N/A?

COUNTIF propagates errors. Clean the source data first, or wrap the range in IFERROR inside a helper column and count distinct values on that helper column instead.