How to Count Unique Values in a Column Using Excel Formula?
Counting unique values in a column is a frequent task when working with large data sets inΒ Microsoft Excel. Unique values are those that appear only once in a given range, and this information is useful for analyzing trends, calculating statistics, and ensuring data quality. Fortunately,Β ExcelΒ provides several functions and formulas to help count unique values quickly and efficiently.
In this article, we will explore different ways to count unique values in a column usingΒ Excel formulas, including examples, step-by-step instructions, and useful tips.
Methods to Count Unique Values in Excel
There are several ways to count unique values in Excel, depending on your needs. We will cover three main methods:
- Using theΒ COUNTIFΒ function.
- Using theΒ SUMPRODUCTΒ andΒ COUNTIFΒ combination.
- Using theΒ UNIQUEΒ function (Excel 365 and Excel 2021).
Method 1: Counting Unique Values Using the COUNTIF Formula
TheΒ COUNTIFΒ function is a powerful tool that counts the number of times a specified value appears in a range. We can useΒ COUNTIFΒ in combination with an array formula to count unique values.
Step-by-Step Instructions
- Select the range where you want to count unique values. For example, if you want to count unique values in column A, select column A.
- Enter the following formula into a new cell:
=SUM(1/COUNTIF(A2:A10, A2:A10)) - PressΒ Ctrl + Shift + EnterΒ to execute the array formula.
This formula divides 1 by theΒ COUNTIFΒ result, which counts how many times each value appears. TheΒ SUMΒ function then adds these values together, resulting in a count of the unique values in the range.
Example:
Letβs say we have the following list of values inΒ column A:
| A |
|---|
| Apple |
| Banana |
| Apple |
| Orange |
| Banana |
| Pear |
| Orange |
TheΒ COUNTIFΒ formulaΒ =SUM(1/COUNTIF(A2:A8, A2:A8))Β will count only unique values such as βApple,β βBanana,β βOrange,β and βPear,β ignoring the duplicates.
Result: 4
Explanation:
- TheΒ COUNTIFΒ function counts how many times each item appears in the column.
- Dividing 1 by this count ensures that duplicates contribute less to the final sum, effectively giving a count of unique values.
Method 2: Counting Unique Values Using SUMPRODUCT and COUNTIF
If you prefer not to use an array formula, the combination ofΒ SUMPRODUCTΒ andΒ COUNTIFΒ functions can be a powerful alternative.
Step-by-Step Instructions
- Select the column where you want to count unique values.
- Enter the following formula in a new cell:
=SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10)) - PressΒ EnterΒ to apply the formula.
Example:
Using the same data set as the previous example,Β SUMPRODUCTΒ withΒ COUNTIFΒ will produce the same result:
| A |
|---|
| Apple |
| Banana |
| Apple |
| Orange |
| Banana |
| Pear |
| Orange |
Formula:Β =SUMPRODUCT(1/COUNTIF(A2:A8, A2:A8))
Result: 4
Explanation:
- COUNTIFΒ counts the occurrences of each value, andΒ SUMPRODUCTΒ ensures that only unique values are counted by adding the inverses of these counts.
Method 3: Counting Unique Values Using the UNIQUE Function (Excel 365/2021)
If youβre usingΒ Excel 365Β orΒ Excel 2021, thereβs a more straightforward approach to counting unique values using theΒ UNIQUEΒ function.
Step-by-Step Instructions
- Select the column containing the data you want to analyze.
- In a new cell, enter the following formula:
=COUNTA(UNIQUE(A2:A10)) - PressΒ EnterΒ to see the result.
Example:
| A |
|---|
| Apple |
| Banana |
| Apple |
| Orange |
| Banana |
| Pear |
| Orange |
Formula:Β =COUNTA(UNIQUE(A2:A8))
Result: 4
Explanation:
- TheΒ UNIQUEΒ function returns a list of unique values from the specified range.
- COUNTAΒ counts the number of items in this unique list, giving you the total number of unique values.
Using Advanced Filter to Count Unique Values
Apart from formulas,Β ExcelΒ offers a built-in tool calledΒ Advanced FilterΒ that allows you to filter out unique values and count them manually. Hereβs how to use it:
Step-by-Step Instructions
- Select the range of data you want to analyze.
- Go to theΒ DataΒ tab and click onΒ AdvancedΒ under theΒ Sort & FilterΒ group.
- In the dialog box, select βCopy to another location.β
- Check the box for βUnique records only.β
- In theΒ Copy toΒ box, choose a destination for the unique values.
- ClickΒ OKΒ to generate the list of unique values in the specified location.
- Use theΒ COUNTAΒ function on this new list to count the unique values.
Example:
| A |
|---|
| Apple |
| Banana |
| Apple |
| Orange |
| Banana |
| Pear |
| Orange |
After applyingΒ Advanced FilterΒ and copying the unique values to a new location, you will get a list:
| B |
|---|
| Apple |
| Banana |
| Orange |
| Pear |
Formula:Β =COUNTA(B2:B5)
Result: 4
Handling Duplicates and Blanks While Counting Unique Values
When counting unique values in a column, you might encounter two common issues: duplicate values and blank cells.
1. Ignoring Duplicates:
In the formulas weβve discussed, duplicates are automatically excluded. However, if you want to count distinct values (unique plus first occurrences of duplicates), you can use:
=SUM(IF(FREQUENCY(IF(A2:A10<>"",MATCH(A2:A10,A2:A10,0)),ROW(A2:A10)-ROW(A2)+1),1))
This array formula counts distinct values while ignoring repeated ones.
2. Ignoring Blank Cells:
If your range contains blank cells, you may want to exclude them from the count. For theΒ COUNTIFΒ method, you can adjust the formula like this:
=SUM(IF(FREQUENCY(IF(A2:A10<>"",MATCH(A2:A10,A2:A10,0)),ROW(A2:A10)-ROW(A2)+1),1))
This formula ensures that blank cells are ignored while counting unique values.
Common Scenarios for Counting Unique Values in a Column
Letβs look at some real-world scenarios where counting unique values inΒ ExcelΒ is important:
Scenario 1: Sales Data Analysis
Imagine you have a list of customer names in column A and you want to find out how many unique customers made purchases. By using the formulas discussed earlier, you can quickly calculate the number of distinct customers.
Scenario 2: Inventory Management
In a list of products, some items may appear multiple times due to reordering or multiple transactions. Counting unique product names can help you understand the diversity of your inventory and prevent duplication.
Overview: Counting Unique Values in a Column
Here is a table summarizing the different formulas discussed for counting unique values:
| Method | Formula Example | Suitable for |
|---|---|---|
| COUNTIF with Array Formula | =SUM(1/COUNTIF(A2:A10, A2:A10)) | General Use |
| SUMPRODUCT + COUNTIF | =SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10)) | Non-array alternatives |
| UNIQUE + COUNTA | =COUNTA(UNIQUE(A2:A10)) | Excel 365/2021 users |
| Advanced Filter + COUNTA | Use Advanced Filter, thenΒ =COUNTA(range) | Manual method |
Final Thoughts
CountingΒ unique valuesΒ in Excel is an essential task when dealing with large datasets. Whether youβre working with customer lists, product inventories, or survey data, using the right Excel formulas can help you quickly identify and count distinct values. From using theΒ COUNTIFΒ formula to leveraging theΒ UNIQUEΒ function in newer versions of Excel, there are plenty of options to suit different needs.
FAQs
How do I count unique values in Excel?
You can count unique values in Excel using the COUNTIF function with an array formula, or by using the UNIQUE function if youβre on Excel 365 or Excel 2021.
What is the difference between distinct and unique values in Excel?
Unique values are those that appear only once in the data, while distinct values include all unique values plus the first occurrence of any duplicates.
Can I count unique values in Excel without using a formula?
Yes, you can use Excelβs Advanced Filter tool to filter unique records and then count them manually using the COUNTA function.
How can I ignore blank cells when counting unique values?
You can modify the formula to exclude blank cells by using the IF function within the COUNTIF or SUMPRODUCT formula, such as IF(A2:A10<>\β\β, β¦).
Which Excel version supports the UNIQUE function?
The UNIQUE function is available in Excel 365 and Excel 2021. It allows you to easily return a list of unique values from a range.
Can I count unique text and numbers together in Excel?
Yes, the formulas discussed such as COUNTIF and UNIQUE work for both text and numbers in the same range.

Vaishvi Desai is the founder of Excelsamurai and a passionate Excel enthusiast with years of experience in data analysis and spreadsheet management. With a mission to help others harness the power of Excel, Vaishvi shares her expertise through concise, easy-to-follow tutorials on shortcuts, formulas, Pivot Tables, and VBA.
