In Excel, managing data often means counting unique values. There's no direct COUNTUNIQUE function like in Google Sheets. But, you can use Excel functions to get the job done. This blog will show you how to count unique values in Excel with examples.
What Does “COUNTUNIQUE” Do?
The "COUNTUNIQUE" function counts unique values in a range or list. For example, it counts how many different numbers or text entries you have, ignoring duplicates.
Excel doesn't have a direct COUNTUNIQUE function. But, you can use COUNTIF, SUMPRODUCT, and UNIQUE (in Excel 365 and 2021) to get the same result. Let's explore these methods!
Method 1: Using COUNTIF with an Array Formula
This method combines COUNTIF and an array formula to count unique values.
Example
Let's say we have a list of numbers in column A:
A |
---|
1 |
2 |
2 |
3 |
3 |
3 |
To count unique numbers in column A, use this formula:
=SUM(1/COUNTIF(A1:A6, A1:A6))
Explanation:
- COUNTIF(A1:A6, A1:A6) gives an array of counts for each value in the range (A1:A6).
- The formula 1/COUNTIF(A1:A6, A1:A6) divides 1 by the count of each value, giving a fraction for duplicates (e.g., "2" and "3").
- Then, SUM() adds up the unique instances, giving the count of distinct values.
Important: After typing the formula, press Ctrl + Shift + Enter to make it an array formula (in older Excel versions).
Method 2: Using SUMPRODUCT and COUNTIF
Another way to count unique values is by using SUMPRODUCT and COUNTIF. This method doesn't need array formulas and is simpler for some users.
Example
Using the same list of numbers in column A, enter this formula:
=SUMPRODUCT(1/COUNTIF(A1:A6, A1:A6))
Explanation:
- COUNTIF(A1:A6, A1:A6) returns an array of counts for each value in the range.
- 1/COUNTIF(A1:A6, A1:A6) produces an array of fractions (the inverse of each count).
- SUMPRODUCT then sums these fractions, giving the unique count.
This method is easier because it doesn't require array entry (no need to press Ctrl + Shift + Enter).
Method 3: Using the UNIQUE Function (Excel 365 / Excel 2021)
If you're using Excel 365 or Excel 2021, you have access to the UNIQUE function. It makes it easy to get unique values from a range. Then, you can count these values.
Example
Given the list of numbers in column A:
A |
---|
1 |
2 |
2 |
3 |
3 |
3 |
To get the unique values, use the UNIQUE function:
=UNIQUE(A1:A6)
This will return the following array of unique values:
B |
---|
1 |
2 |
3 |
To count how many unique values there are, wrap the UNIQUE function in the COUNTA function:
=COUNTA(UNIQUE(A1:A6))
This will return 3, as there are three distinct values in the list: 1, 2, and 3.
Method 4: Using a Pivot Table
If you prefer a visual solution, you can use a Pivot Table to count unique values in a range. Here's how:
Steps:
- Select the range of data (e.g., A1:A6).
- Go to the Insert tab and select PivotTable.
- In the PivotTable Fields pane, drag the field (column) to both Rows and Values.
- In the Values section, click the drop-down arrow next to the field, then choose Value Field Settings.
- Choose Count to count the unique entries.
While this is not a formula-based method, it provides a quick and effective way to analyze unique values.
Method 5: Using COUNTIFS with Multiple Criteria (Advanced)
For more complex datasets, you might want to count unique values based on multiple criteria. For example, counting unique items only in certain categories. In these cases, you can use the COUNTIFS function to apply multiple conditions.
Example
Assume you have two columns: Category and Value. You want to count how many unique values exist for a specific category.
Category | Value |
---|---|
A | 1 |
A | 2 |
B | 2 |
A | 3 |
B | 3 |
A | 3 |
To count unique values in Category A, you can use this formula:
=SUM(1/COUNTIFS(A1:A6, "A", B1:B6, B1:B6))
This formula counts unique values in column B where the category is "A".
Conclusion
Excel does not have a direct COUNTUNIQUE function. But, you can use several techniques to get the same result. Whether you prefer array formulas, SUMPRODUCT, or the new UNIQUE function in Excel 365, there are many ways to count unique values.
The right method depends on your Excel version and needs. Choose the approach that best fits your situation. Enjoy streamlined data analysis!