# How to Count Unique Values in Excel

When working with a database, it is common to have duplicated values in the working sheet, and you may need to count the unique values in a range. You can use the COUNTIF and SUMPRODUCT functions to determine the unique count.

The COUNTIF function counts the number of cells that meet a criterion, and the SUMPRODUCT function returns the product of numbers in an array.

Example: In the following database, the city is in column A, and the temperature is in column B.

Formula: How many unique values are in column B?

=SUMPRODUCT(1/COUNTIF(B2:B12,B2:B12))

• Step 1: COUNTIF(B2:B12, B2:B12) is to count the frequency of each value (e.g., the frequency of 7 is 3);
• Step 2: 1/COUNTIF(B2:B12, B2:B12) is to transfer the frequency into the fraction (e.g., each seven will be 1/3);
• Step 3: The SUMPRODUCT function returns the sum of the products of the new array.

In the example, there are eight unique values in column B.

The following table shows the steps to get the number of unique values:

Notes: The SUMPRODUCT Function

The SUMPRODUCT function adds all the multiplication results for all arrays.

Formula:

=SUMPRODUCT(array1, [array2], …)

Explanations:

– Array1 is required; the first array is to multiply and then add.
– Array2 is optional; the second array is to multiply and then add.