Smart Systems for Home

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

Count Unique Text Values in Excel? (Formulas)

· 4 min read · Home Tech

In this article
  1. Why Counting Unique Text Values Is Tricky
  2. The Modern Solution: UNIQUE Function (Excel 365 & 2021)
  3. Classic Formula for Older Excel (No UNIQUE)
  4. Counting Unique Text with Conditions (e.g., Only “Yes” in Another Column)
  5. Common Mistakes and How to Avoid Them
  6. Alternative Methods: Pivot Tables and Power Query
  7. Frequently Asked Questions

To count unique text values in a range in Excel, use the formula =SUMPRODUCT(--(FREQUENCY(MATCH(range,range,0),ROW(range)-ROW(range first cell)+1)>0)) for a single column, or the simpler =COUNTA(UNIQUE(range)) if you have Excel 365 or Excel 2021. The UNIQUE function is the modern, easiest method, while the FREQUENCY/MATCH combo works in older versions.

Why Counting Unique Text Values Is Tricky

Excel’s built-in COUNTIF or COUNTIFS functions count cells that meet a condition, but they count every occurrence. If a list contains “Apple” three times, COUNTIF returns 3, not 1. To count unique items, you need to tell Excel to look at each value only once. This is not a built-in single function in older Excel versions, which is why users often resort to complex formulas or pivot tables.

The Modern Solution: UNIQUE Function (Excel 365 & 2021)

If you have Microsoft 365 or Excel 2021, the UNIQUE function is the cleanest way. It returns a list of all distinct values in a range, and you can wrap it in COUNTA to count them.

  • Count unique text (including blanks ignored): =COUNTA(UNIQUE(A2:A100))
  • Count unique text (including empty cells as a value): =SUMPRODUCT(--(UNIQUE(A2:A100)< >"")) (adjust as needed)
  • Count unique text and numbers together: =COUNTA(UNIQUE(A2:A100)) works for any data type.

Note: UNIQUE returns a dynamic array that spills into adjacent cells. If you see a #SPILL! error, it means something is blocking the output range. Clear the cells below or to the right of your formula.

Classic Formula for Older Excel (No UNIQUE)

For Excel 2019 and earlier, you can use an array formula with FREQUENCY and MATCH. This works for text and numbers mixed, but it’s important to enter it correctly.

  1. Assume your data is in A2:A100 (adjust the range).
  2. Enter this formula: =SUMPRODUCT(--(FREQUENCY(MATCH(A2:A100,A2:A100,0),ROW(A2:A100)-ROW(A2)+1)>0))
  3. Press Ctrl+Shift+Enter if you are using Excel 2019 or earlier (in Excel 365, it works as a normal formula).

How it works: MATCH finds the position of each value’s first occurrence, FREQUENCY counts how many times each position appears, and SUMPRODUCT counts how many positions have a frequency greater than zero (i.e., unique items).

Counting Unique Text with Conditions (e.g., Only “Yes” in Another Column)

Sometimes you need to count unique text values that meet a condition, like counting distinct customers who made a purchase in a specific region. In Excel 365, you can combine UNIQUE and FILTER:

  • Example: Count unique products in column A where column B says “Active”.
    =COUNTA(UNIQUE(FILTER(A2:A100, B2:B100="Active")))
  • For older Excel, you would need a more complex array formula with FREQUENCY and IF.

If you have a large dataset, the FILTER approach is faster and easier to read.

Common Mistakes and How to Avoid Them

  • Counting blanks: COUNTA(UNIQUE(range)) ignores empty cells, which is usually what you want. If you want to count blanks as a unique value, use ROWS(UNIQUE(range)) instead.
  • Trailing spaces: “Apple” and “Apple ” are treated as different values. Use TRIM to clean data first: =COUNTA(UNIQUE(TRIM(A2:A100))) (in Excel 365).
  • Case sensitivity: By default, Excel is case-insensitive, so “apple” and “APPLE” are the same. If you need case-sensitive counting, you’ll need a more advanced formula.
  • #SPILL! error: This happens when the UNIQUE result can’t fit because other cells are not empty. Clear the spill range.
  • Using COUNTIF with UNIQUE: Don’t use =COUNTIF(UNIQUE(A2:A100),"*") because COUNTIF doesn’t work with dynamic arrays in all versions.

Alternative Methods: Pivot Tables and Power Query

If you prefer a non-formula approach, a Pivot Table is a reliable way to count unique values. Drag the field to the Rows area, then right-click and set the Value Field Settings to “Distinct Count” (available in Excel 2013 and later). This is especially useful for large datasets because it’s fast and doesn’t require array formulas.

Power Query (Get & Transform) is another option: load your range, remove duplicates, and count the rows. This is a manual, one-time process, but it’s great for cleaning data before analysis.

Frequently Asked Questions

How do I count unique text values in a column with blanks?

If you use =COUNTA(UNIQUE(A2:A100)), blanks are ignored. If you want to include blanks as a unique value, use =ROWS(UNIQUE(A2:A100)) which counts all distinct entries, including empty cells.

Why does my UNIQUE formula return a #VALUE! error?

This usually happens when you are using an older Excel version that doesn’t support dynamic arrays. Check your Excel version. If you have Excel 2019 or earlier, use the FREQUENCY/MATCH formula instead.

Can I count unique text values across multiple columns?

Yes, but it’s more complex. In Excel 365, you can combine ranges with VSTACK (e.g., =COUNTA(UNIQUE(VSTACK(A2:A100, C2:C100)))). For older versions, you would need a more advanced array formula or a Pivot Table with multiple fields.

How do I count unique text values that appear more than once?

To count values that appear at least twice, use =SUMPRODUCT(--(COUNTIF(A2:A100, A2:A100)>1)) and then divide by something? Actually, that counts the total occurrences, not unique values. To count unique values that appear more than once, use =SUMPRODUCT(--(COUNTIF(A2:A100, A2:A100)>1)/COUNTIF(A2:A100, A2:A100)) – but this is an array formula. A simpler way is to use UNIQUE and then filter by count.

Is there a way to count unique text values without using formulas?

Yes, use a Pivot Table with “Distinct Count” in the Value Field Settings. This requires Excel 2013 or later and is often the fastest method for large datasets.