How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (2024)

Home > Microsoft Excel > How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values

(Note: This guide on how to freeze rows in Excel is suitable for all Excel versions includingOffice 365)

Working with large amounts of data in Excel can be quite difficult. Some values may be repeated more than once. You might have to take into account multiple entries of data while performing any function to upgrade your accuracy. You will also need to count the values to organize or even acquire statistics from the data.

With large data, it would be nearly impossible to count the values manually. Especially, keeping a track of unique or distinct values can be quite arduous. Fortunately in Excel, there are many ways to count unique and distinct values.

You’ll Learn:

  • Unique and Distinct Values
  • How to Count Unique Values in Excel
    • Using SUM, IF, and COUNTIF Functions
      • Count Unique Text Values in Excel
      • Count Unique Numeric Values in Excel
  • How to Count Distinct Values in Excel
    • Using Filter Option
    • Using SUM and COUNTIF functions

First, let us understand the difference between Unique and Distinct Values.

Unique and Distinct Values

Data can be repeated or unrepeated. These unrepeated data are of two types. They are called unique data and distinct data.

Unique data are those which occur in the dataset only once.

Whereas, distinct data include the duplicate values but count them only once.

I will explain unique and distinct data with an example for better understanding.

Consider an example, where column A has the list of people and column B lists their favorite colors.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (1)

In this, red, green, and purple colors occur only once, so they are called unique elements. Therefore the unique elements count is 3

Whereas, there are 8 distinct elements. That is the colors, though repeated are counted once. The colors are red, green, yellow, blue, white, black, gray, and purple. So, the distinct value count is 8.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (2)

In this guide, I will show you how to count unique and distinct values in Excel.

Let’s dive in.

How to Count Unique Values in Excel

First, let us see how to count unique values in excel.

Using SUM, IF, and COUNTIF Functions

In Excel, functions are always available to solve any operations. In this case, you can use a combination of SUM, IF and COUNTIF functions to count unique values in Excel.

To count unique values, enter the formula =SUM(IF(COUNTIF(range, range)=1,1,0)) in the desired cell. The range denotes the starting cell and the ending cell.

This is an array formula where the count values are stored in a new array. Since this is an array formula, make sure you press Ctrl+Shift+Enter after entering the formula. Also, note that when you enter the formula, curly braces will automatically populate at the end of them. But, do not enter them manually.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (3)

Consider the above example. To calculate the unique values in the given Excel sheet, enter the formula in the destination cell.

In the place of range, enter the cells which contain the elements whose unique value is to be found. Here, cells B3 to B16 house the said elements. So the formula becomes:

=SUM(IF(COUNTIF(B3:B16, B3:B16)=1,1,0))

Now, press Ctrl+Shift +Enter. This gives the count of unique values in the selected range. The unique value count is 3.

Simple, right? Now, let me explain how this formula gives the unique values in 3 simple steps.

  1. The COUNTIF function counts the number of unique values in the given range B3 to B16. That is the number of times the value is repeated in the range. These counted values are stored in an array. So, the array becomes [1,1,2,3,2,3,2,2,2,2,2,3,1,2]
  2. Then the IF function keeps the unique values(=1) and replaces anything other than 1 with 0. So the array becomes [1,1,0,0,0,0,0,0,0,0,0,0,1,0]
  3. Now finally, the SUM function adds the unique value and returns the value 3.

There are two additional cases while using the SUM, IF, and COUNTIF functions. You can use them to find either unique text values or numeric values in Excel.

Count Unique Text Values in Excel

In some tables and worksheets, some texts might be intertwined with numbers. In such cases, you can use the above-mentioned function with a little modification to find the unique text values in Excel.

Enter the formula =SUM(IF(ISTEXT(range)*COUNTIF(range,range)=1,1,0)) in the destination cell and press Ctrl+Shift+Enter. The range denotes the start and end cells that house the elements.

From the general formula, we have added the ISTEXT element to find the unique text values. If the value is a text, the ISTEXT function returns 1 and the value is counted in an array. If the cell houses a non-text value, it returns zero.

The functionality is also similar to the above common formula.

Count Unique Numeric values in Excel

This is a vice versa to the above-mentioned case. In case you only want to count unique numeric values intertwined with texts, you can use the below formula.

Enter the formula =SUM(IF(ISNUMBER(range)*COUNTIF(range,range)=1,1,0)) in the desired cell. The range denotes the start and end cells that hold the values.

Here, the ISNUMBER function returns 1 for numeric values and ignores other values. This function’s working is also similar to the above-mentioned case.

Note: In Excel, date and time are counted as numbers, so they are also counted.

We have seen how to count unique values in excel, we can also count distinct values by using the methods below.

How to Count Distinct Values in Excel

In Excel, there are two easy methods to find the number of distinct values.

Using Filter Option

This is an easy and simple method in Excel which gives you the unique values in your data. In this method, you can use the Filter option to pick out the distinct values. This option filters the elements to another row. then, you can use the ROWS function to find out the number of unique elements.

To find the unique rows using the Filter option, first select the rows/columns which have the duplicate elements.

Then, go to Data > Sort & Filter and click on Advanced.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (4)

The Advanced Filter dialog box appears.

Specify the List range: i.e select the cells you need to apply the filter to. You can enter them manually, or click on the Collapse button How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (5), select the area and click Expand .

First, select the Copy to another location. This copied the unique elements onto a new column.

Now, use the collapse and expand button to select the rows you want the unique elements to be copied.

Finally, check Unique records only. And click OK.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (6)

Thus the distinct elements are copied onto a new row.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (7)

To calculate the row count, you can select the columns and click on Quick analysis or Ctrl + Q. Select Totals and click on Row Count. This will give you the row count right below the unique elements.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (8)

Or, you can use the function =ROWS(a:b), where a and b are the starting and ending cells respectively.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (9)

Note: If you click on Filter the list, in-place, the selected values will be replaced in the same column.

Using SUM and COUNTIF functions

You can use the SUM and COUNTIF functions to calculate the distinct values in Excel. In this case, we will inverse the COUNTIF function to arrive at distinct values.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (10)

To count distinct values in excel, first enter the formula =SUM(1/COUNTIF(range, range)) in the desired cell. The range specifies the starting cell and ending cell separated by a colon. This is an array function, so press Ctrl+Shift+Enter to apply the formula.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (11)

Alternatively, you can also use the formula =SUMPRODUCT(1/COUNTIF(range, range)) in the desired cell to count distinct values. This is not an array function, so pressing Enter is sufficient to apply the formula.

Consider the same above-mentioned example. To count the distinct values, enter the formula =SUM(1/COUNTIF(B3:B16, B3:B16)) in the destination cell. Here, the range is B3:B16, so the values in cells B3 to B16 are taken into account.

First, the COUNTIF function counts the number of times the values occur in the given range. This value is stored in an array. Then, this value is divided by 1. So, if a value occurs twice, the value after dividing by 1 will be 0.5. Now, the SUM or SUMPRODUCT function adds up the fractional values and returns the result which is equal to the count of distinct values in the range.

Note: Similarly, you can also tweak the formulae a little to find distinct text values or distinct numeric values.

To find distinct text values: =SUM(IF(ISTEXT(range),1/COUNTIF(range, range),””))

To find distinct text values: =SUM(IF(ISNUMBER(range),1/COUNTIF(range, range),””))

Closing Thoughts

Finding the unique and distinct elements in a large dataset can be used to determine the statistics or probability of the data.

In this guide, we saw how to count unique and distinct values in Excel. Based on your specifications and preferences, you can either find the count of unique or distinct values.

If you need more high-quality Excel guides, please check out our free Excel resources center.

Simon Sez IT has been teaching Excel for over ten years. For a low, monthly fee you can get access to 100+ IT training courses. Click here for advanced Excel courses with in-depth training modules.

Simon Calder
How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (12)

Chris “Simon” Calder was working as a Project Manager in IT for one of Los Angeles’ most prestigious cultural institutions, LACMA.He taught himself to use Microsoft Project from a giant textbook and hated every moment of it. Online learning was in its infancy then, but he spotted an opportunity and made an online MS Project course - the rest, as they say, is history!

I am an expert in Microsoft Excel with a demonstrable depth of knowledge and hands-on experience in working with large datasets. My proficiency extends to various Excel versions, including Office 365. I have a thorough understanding of advanced Excel functions and features, allowing me to efficiently manipulate and analyze data.

Now, let's delve into the concepts covered in the article "How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values."

Unique and Distinct Values

The article begins by explaining the difference between unique and distinct values. Unique data are those that occur only once in a dataset, while distinct data include duplicate values but count them only once.

How to Count Unique Values in Excel

Using SUM, IF, and COUNTIF Functions

The article introduces a method using a combination of SUM, IF, and COUNTIF functions to count unique values in Excel. The formula is =SUM(IF(COUNTIF(range, range)=1,1,0)), where the range represents the cells containing the elements whose unique values need to be determined.

The process involves creating an array of counted values using COUNTIF, filtering out non-unique values with IF, and then summing up the array to get the count of unique values.

Count Unique Text Values in Excel

For scenarios where text values are intertwined with numbers, a modification of the formula is provided: =SUM(IF(ISTEXT(range)*COUNTIF(range,range)=1,1,0)). This modification incorporates the ISTEXT function to identify and count unique text values.

Count Unique Numeric Values in Excel

Conversely, if the goal is to count unique numeric values, the formula is adjusted to =SUM(IF(ISNUMBER(range)*COUNTIF(range,range)=1,1,0)). The ISNUMBER function is used to identify numeric values in this case.

How to Count Distinct Values in Excel

Using Filter Option

The article outlines an easy method to find distinct values by using the Filter option. This involves selecting rows or columns with duplicate elements, applying the Advanced Filter, copying unique elements to a new column, and then using the ROWS function to count distinct values.

Using SUM and COUNTIF Functions

An alternative method for counting distinct values is introduced. The formula is =SUM(1/COUNTIF(range, range)), and it involves inverting the COUNTIF function. This approach creates an array of fractional values, which, when summed up, gives the count of distinct values in the specified range.

Closing Thoughts

The article concludes by emphasizing the importance of finding unique and distinct elements in a dataset for statistical and probabilistic analysis. It encourages readers to explore more high-quality Excel guides and resources.

In summary, the article provides a comprehensive guide on counting unique and distinct values in Excel, catering to different scenarios and types of data.

How to Count Unique Values in Excel? 3 Easy Ways to Count Unique and Distinct Values (2024)
Top Articles
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 6407

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.