How to do distinct count in excel

Count unique values among duplicates

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 More…Less

Let’s say you want to find out how many unique values exist in a range that contains duplicate values. For example, if a column contains:

  • The values 5, 6, 7, and 6, the result is three unique values — 5 , 6 and 7.

  • The values «Bradley», «Doyle», «Doyle», «Doyle», the result is two unique values — «Bradley» and «Doyle».

There are several ways to count unique values among duplicates.

You can use the Advanced Filter dialog box to extract the unique values from a column of data and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range.

  1. Select the range of cells, or make sure the active cell is in a table.

    Make sure the range of cells has a column heading.

  2. On the Data tab, in the Sort & Filter group, click Advanced.

    The Advanced Filter dialog box appears.

  3. Click Copy to another location.

  4. In the Copy to box, enter a cell reference.

    Alternatively, click Collapse Dialog Button image to temporarily hide the dialog box, select a cell on the worksheet, and then press Expand Dialog Button image.

  5. Select the Unique records only check box, and click OK.

    The unique values from the selected range are copied to the new location beginning with the cell you specified in the Copy to box.

  6. In the blank cell below the last cell in the range, enter the ROWS function. Use the range of unique values that you just copied as the argument, excluding the column heading. For example, if the range of unique values is B2:B45, you enter =ROWS(B2:B45).

Use a combination of the IF, SUM, FREQUENCY, MATCH, and LEN functions to do this task:

  • Assign a value of 1 to each true condition by using the IF function.

  • Add the total by using the SUM function.

  • Count the number of unique values by using the FREQUENCY function. The FREQUENCY function ignores text and zero values. For the first occurrence of a specific value, this function returns a number equal to the number of occurrences of that value. For each occurrence of that same value after the first, this function returns a zero.

  • Return the position of a text value in a range by using the MATCH function. This value returned is then used as an argument to the FREQUENCY function so that the corresponding text values can be evaluated.

  • Find blank cells by using the LEN function. Blank cells have a length of 0.

Examples of nested functions to count the number of unique values among duplicates

Notes: 

  • The formulas in this example must be entered as array formulas. If you have a current version of Microsoft 365, then you can simply enter the formula in the top-left-cell of the output range, then press ENTER to confirm the formula as a dynamic array formula. Otherwise, the formula must be entered as a legacy array formula by first selecting the output range, entering the formula in the top-left-cell of the output range, and then pressing CTRL+SHIFT+ENTER to confirm it. Excel inserts curly brackets at the beginning and end of the formula for you. For more information on array formulas, see Guidelines and examples of array formulas.

  • To see a function evaluated step by step, select the cell containing the formula, and then on the Formulas tab, in the Formula Auditing group, click Evaluate Formula.

  • The FREQUENCY function calculates how often values occur within a range of values, and then returns a vertical array of numbers. For example, use FREQUENCY to count the number of test scores that fall within ranges of scores. Because this function returns an array, it must be entered as an array formula.

  • The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. For example, if the range A1:A3 contains the values 5, 25, and 38, the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.

  • The LEN function returns the number of characters in a text string.

  • The SUM function adds all the numbers that you specify as arguments. Each argument can be a range, a cell reference, an array, a constant, a formula, or the result from another function. For example, SUM(A1:A5) adds all the numbers that are contained in cells A1 through A5.

  • The IF function returns one value if a condition you specify evaluates to TRUE, and another value if that condition evaluates to FALSE.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

See Also

Filter for unique values or remove duplicate values

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Right-click on any value in column B. Go to Value Field Settings. In the Summarize Values By tab, go to Summarize Value field by and set it to Distinct Count.
Click OK.

  1. Column F will now contain the distinct values.
  2. Select H6.
  3. Enter the formula =ROWS(F3:F9) . Click Enter.

Contents

  • 1 How do I turn on distinct counts in Excel?
  • 2 How do I count without duplicates in Excel?
  • 3 What is distinct count?
  • 4 How do you write a Countif criteria?
  • 5 How do you count unique values in sheets?
  • 6 How do I use Countif for duplicates?
  • 7 How do I get distinct values from multiple columns in Excel?
  • 8 Can you count distinct in Excel pivot?
  • 9 How do you use distinct?
  • 10 Does Count distinct include Null?
  • 11 How do you count similar data in sheets?
  • 12 How do I use Countif to find duplicates in two columns?
  • 13 How do I group duplicates in Excel?
  • 14 How do you highlight duplicates in sheets?
  • 15 How do I get unique values from multiple columns?
  • 16 How do I get unique values in two columns?
  • 17 How do you count occurrences in a pivot table?
  • 18 What is the difference between count and distinct count?
  • 19 How do you SELECT distinct from one column?
  • 20 How does SELECT distinct work?

How do I turn on distinct counts in Excel?

To get the distinct count in the Pivot Table, follow the below steps:

  1. Right-click on any cell in the ‘Count of Sales Rep’ column.
  2. Click on Value Field Settings.
  3. In the Value Field Settings dialog box, select ‘Distinct Count’ as the type of calculation (you may have to scroll down the list to find it).
  4. Click OK.

How do I count without duplicates in Excel?

In the Formulas Helper dialog box, you need to:

  1. Find and select Count unique values in the Choose a formula box; Tip: you can check the Filter box, type in certain words to filter the formula names.
  2. In the Range box, select the range in which you want to count unique values;
  3. Click the OK button.

What is distinct count?

The COUNT DISTINCT function returns the number of unique values in the column or expression, as the following example shows. SELECT COUNT (DISTINCT item_num) FROM items;If every column value is NULL, the COUNT DISTINCT function returns zero (0).

How do you write a Countif criteria?

The result is 4. Counts the number of cells that have exactly 7 characters, and end with the letters “es” in cells A2 through A5. The question mark (?) is used as the wildcard character to match individual characters. The result is 2.

How do you count unique values in sheets?

Here is how to use this formula:

  1. In an empty cell type the beginning of the formula =COUNTUNIQUE and press Tab on your keyboard to enter the formula.
  2. Select your range of data that you want to count unique values for.
  3. Add and closing parenthesis “)” and press Enter on your keyboard.

How do I use Countif for duplicates?

Tip: If you want to count the duplicates in the whole Column, use this formula =COUNTIF(A:A, A2) (the Column A indicates column of data, and A2 stands the cell you want to count the frequency, you can change them as you need).

How do I get distinct values from multiple columns in Excel?

  1. Since both are array formulas, be sure to press Ctrl + Shift + Enter to complete them correctly.
  2. To quickly select the unique or distinct list including column headers, filter unique values, click on any cell in the unique list, and then press Ctrl + A.

Can you count distinct in Excel pivot?

In the Value Field Settings dialog, click Summarize Values By tab, and then scroll to click Distinct Count option, see screenshot: 5. And then click OK, you will get the pivot table which count only the unique values.

How do you use distinct?

How to use distinct in SQL?

  1. SELECT DISTINCT returns only distinct (different) values.
  2. DISTINCT eliminates duplicate records from the table.
  3. DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc.
  4. DISTINCT operates on a single column.
  5. Multiple columns are not supported for DISTINCT.

Does Count distinct include Null?

The DISTINCT clause counts only those columns having distinct (unique) values.COUNT DISTINCT does not count NULL as a distinct value.

How do you count similar data in sheets?

To add the COUNTIF function to the spreadsheet, select cell B9 and click in the fx bar. Enter ‘=COUNTIF(A2:A7, “450”)‘ in the fx bar, and press the Return key to add the function to the cell. Cell B9 will now include the value 2. As such, it counts two duplicate ‘450’ values within the A2:A7 cell range.

How do I use Countif to find duplicates in two columns?

Microsoft Excel has made finding duplicates very easy. We can combine the COUNTIF and AND functions to find duplicates between columns.
To find out whether the names in column B are duplicates, we need to:

  1. Go to cell C2.
  2. Assign the formula =AND(COUNTIF($A$2:$A$6, A2),COUNTIF($B$2:$B$6, A2)) in C2.
  3. Press Enter.

How do I group duplicates in Excel?

3. How to group duplicates together

  1. Next, click any cell in your table.
  2. Select the Data tab.
  3. Click the large Sort button (not the little AZ or ZA icons)
  4. In the Sort By drop-down list, select the column that contains the highlighted duplicates.
  5. Change Sort On to Cell Color.

How do you highlight duplicates in sheets?

Google Sheets: How to highlight duplicates in a single column

  1. Open your spreadsheet in Google Sheets and select a column.
  2. For instance, select column A > Format > Conditional formatting.
  3. Under Format rules, open the drop-down list and select Custom formula is.
  4. Enter the Value for the custom formula, =countif(A1:A,A1)>1.

How do I get unique values from multiple columns?

First select the range of the cells. Then go to Home>Conditional Formatting>Highlight Cells Rules>Duplicate Values. You will get a small box called Duplicate Values. Select any color from there to highlight the duplicate values.

How do I get unique values in two columns?

Example: Compare Two Columns and Highlight Mismatched Data
In the Styles group, click on the ‘Conditional Formatting’ option. Hover the cursor on the Highlight Cell Rules option. Click on Duplicate Values. In the Duplicate Values dialog box, make sure ‘Unique’ is selected.

How do you count occurrences in a pivot table?

You can use a PivotTable to display totals and count the occurrences of unique values.
In the Value Field Settings dialog box, do the following:

  1. In the Summarize value field by section, select Count.
  2. In the Custom Name field, modify the name to Count.
  3. Click OK.

What is the difference between count and distinct count?

Count would show a result of all records while count distinct will result in showing only distinct count. For instance, a table has 5 records as a,a,b,b,c then Count is 5 while Count distinct is 3.

How do you SELECT distinct from one column?

“sql select unique rows based on a column” Code Answer’s

  1. DISTINCT.
  2. – select distinct * from employees; ==>
  3. retrieves any row if it has at.
  4. least a single unique column.
  5. – select distinct first_name from employees; ==>
  6. retrieves unique names.
  7. from table. ( removes duplicates)

How does SELECT distinct work?

A SELECT DISTINCT statement first builds our overall result set with all records, i.e including duplicate values based on FROM, JOIN, WHERE, HAVING, etc statements.Then it performs de-duplication (i.e. removes any duplicate values) on the overall result set which was prepared in the first step.

Do you want to count distinct values in a list in Excel?

When performing any data analysis in Excel you will often want to know the number of distinct items in a column. This statistic can give you a useful overview of the data and help you spot errors or inconsistencies.

This post will show you all the ways you can count the number of distinct items in your list. Get your copy of the example workbook in this post to follow along.

Distinct vs Unique

The terms unique and distinct are often incorrectly interchanged liberally. There is a big difference between these terms.

Distinct means values that are different. The distinct values from this list {A, B, B, C} are {A, B, C}. The count in this case will be 3.

Unique means values that only appear once. The unique values from the list {A, B, B, C} are {A, C}. The count in this case will be 2.

💡 Tip: Check out this post if you are actually looking for a count of unique items.

Count Distinct Values with the COUNTIFS Function

The first way to count the unique values in a range is with the COUNTIFS function.

The COUNTIFS function allows you to count values based on one or more criteria.

= SUM ( 1 / COUNTIFS ( B5:B14, B5:B14 ) )

The above formula will count the number of distinct items from the list of values in the range B5:B14.

The COUNTIFS function is used to see how many times each value appears in the list. When you invert this count you get a fractional value that will add up to 1 for each distinct value in the list.

The SUM function then adds all these fractions up and the total is the number of distinct items in the list.

💡 Tip: If you are working with an older version of Excel that doesn’t support array formulas, then you will need to enter this formula with Ctrl + Shift + Enter.

Count Distinct Values with the UNIQUE Function

Another formula approach to counting the number of distinct items from the list is with dynamic array functions.

However, these are only available in Excel for Microsoft 365.

= COUNTA ( UNIQUE ( B5:B14 ) )

The above formula will return the count of all distinct items from the list in B5:B14.

The UNIQUE function returns all the distinct values from the list. The number of items in the distinct list is then counted using the COUNTA function.

Count Distinct Values with Advanced Filters

Advanced Filters is a feature that allows you to add complex logic based on multiple fields to filter your lists.

This can also be used to filter the distinct values in your list.

You can then use a SUBTOTAL function to count only the visible items in your filtered list.

Here’s how to count the distinct items with the advanced filters.

= SUBTOTAL ( 103, B5:B14 )
  1. Add the above SUBTOTAL function to the range you want to count values from. The 103 argument tells the SUBTOTAL function to only count the visible cells in a range.

  1. Select the column of data in which you want to count distinct values.

  1. Go to the Data tab.
  2. Click on the Advanced command in the Sort and Filter section of the ribbon.

This will open the Advanced Filter menu.

  1. Select the Filter the list in place option from the Action section.
  2. The List range should be the range of values previously selected in step 2. You can update this if needed.
  3. Check the Unique records only option. Even though it says unique, it will actually return the distinct values in the filter.
  4. Press the OK button.

The list is filtered to hide all the repeated values and the SUBTOTAL will then only count the distinct items in the list.

Count Distinct Values with a Pivot Table

You can get a list of distinct values from a pivot table.

When you summarize your data by rows in a pivot table, the rows area will show only the distinct items. You can then count these with the status bar statistics or the COUNTA function.

You will first need to create a pivot table with the data that you want to get a distinct count.

  1. Select the data.
  2. Go to the Insert tab.
  3. Click on the PivotTable command.

This opens the PivotTable from table or range menu where you can select where you want to place the new pivot table.

  1. Choose the location for your new pivot table.
  2. Press the OK button.

This will create a new blank pivot table. When you select any cell inside this pivot table, you will see the PivotTable Fields list appear on the right side of the workbook.

  1. Drag the field from which you want to count distinct items into the Rows area of the pivot table.

This creates a list of distinct items in the pivot table. Now you can select these items and the count will be displayed in the status bar area.

Count Distinct Values with the Pivot Table Data Model

While using a pivot table will get you the list of distinct items from your data, it’s not ideal for counting the results. There is an additional step of selecting the items and getting the count in the status bar.

But there is a way to use a pivot table and return the count of distinct items inside the Values area of the pivot table.

When you use the pivot table data model feature, it will reveal an extra summary type in the field settings that will count distinct values.

You will insert the pivot table as before, but there is an extra step during the process.

  1. Check the Add this data to the Data Model option in the PivotTable from table or range menu.

  1. Drag the field into the Values area. It should default to a count.
  2. Left-click on the field.
  3. Select Value Field Settings from the menu options.

This opens the Value Field Settings menu.

  1. Go to the Summarize Values By tab.
  2. Choose the Distinct Count option in the Summarize value field by list. This option only appears when the data has been added to the data model.
  3. Press the OK button.

That’s it! The distinct count of items now appears in your pivot table.

This is much more versatile as you can now get the distinct count within another categorical grouping by adding a field into the Rows area.

For example, each value in the pivot table is now a distinct count of the car model based on the make.

Count Distinct Values Remove Duplicates

The Remove Duplicates feature will allow you to get rid of any repeated values in your list.

You can then count the results to get a distinct count of items.

  1. Select the range of items to count.
  2. Go to the Data tab.
  3. Click on the Remove Duplicates command.

This will open the Remove Duplicates menu.

  1. Select a single column in the list of Columns.
  2. Press the OK button.

This will remove the duplicates in your list and a popup will show telling you how many items were removed and how many remain. This is the number of distinct items from the list!

📝 Note: This will change the data, so be sure to only perform this command on a copy of your source data so you don’t lose the original.

Count Distinct Values with Power Query Column Distribution

Power Query is a great tool for importing and transforming data.

When building your queries, it will even show you useful summary statistics about the data in the column distribution view. This includes a distinct count.

You will first need to load your data into the Power Query editor to see these features.

  1. Select the data.
  2. Go to the Data tab.
  3. Select the From Table/Range query option.

This will open the Power Query editor and you might already see the column distribution feature with the distinct count.

If you don’t see this, you can enable it from the View tab in the editor.

  1. Go to the View tab.
  2. Check the Column distribution option in the Data Preview section.

💡 Tip: Hover your mouse cursor over the counts and you’ll see a percentage distribution!

Count Distinct Values with Power Query Transform Tab

The column distribution feature is handy for a quick overview of the data, but you might want to get this value back into Excel from your Power Query.

This is also possible.

  1. Select the column you want to count.
  2. Go to the Transform tab.
  3. Click on the Statistics command in the Number Column section.
  4. Select the Count Distinct Values option from the menu.

This returns a sing scalar value from your column which is the count of the distinct items in that column.

You can load this back into Excel and it will load into a single column and single row table. Go to the Home tab and click on the Close and Load button.

Count Distinct Values with VBA

There is no prebuilt function in Excel that will count the number of distinct items in a range.

However, you can build your own custom VBA function for this purpose.

Press the Alt + F11 keyboard shortcut to open the visual basic editor. This is where you can place the code for your user-defined function.

Go to the Insert menu and select the Module option to create a new module for your code.

Function COUNTDISTINCTVALUES(rng As Range) As Integer
Application.Volatile
Dim c As Variant
Dim distinctValues As New Collection

On Error Resume Next
For Each c In rng
    If Not (IsEmpty(c)) Then
        distinctValues.Add c, CStr(c)
    End If
Next c
COUNTDISTINCTVALUES = distinctValues.Count
End Function

Copy and paste the above code into the module.

This code will create a new function named COUNTDISTINCTVALUES which can be used anywhere in the workbook just like any other function.

The will loop through each cell in the range it is passed. If the cell is not empty, then the value in the cell is added to a collection object.

Collections will only allow distinct values to be added, so the end result will be a collection of only the distinct values from your range.

The count of the items in the collection is then returned as the function output!

= COUNTDISTINCTVALUES ( B3:B12 )

The above formula will then return the distinct count of the values in the range B3:B12.

Count Distinct Values with Office Scripts

Office scripts are another way to get a distinct count for a selected range.

You can create a script that will count distinct items in the active range.

Go to the Automate tab and select the New Script option.

This will open the Code Editor.

function main(workbook: ExcelScript.Workbook) {
    let rng = workbook.getSelectedRange();
    let rngValues = rng.getValues();
    let arrayValues = rngValues.reduce((a, value) => a.concat(value), []);
    let distinctValues = new Set(arrayValues);
    console.log(distinctValues.size);
};

Add the above code and press the Save script button.

This code gets the values from the selected range in the sheet. It will then convert this to a one-dimensional array of values with the reduce function.

This 1D array is then added to a Set. Sets also have the property that they only allow distinct values, so the distinctValues set will only have the distinct values from the selected range.

The number of items is counted with the size and this is returned to the console log to give you the count of distinct values.

Conclusions

There are several options for counting the distinct number of items in a list.

Formulas solutions are great for dynamic live results directly in your sheet. Other features such as advanced filters or remove duplicates are only suited for one-time uses.

If you’re already using Pivot Tables or Power Query in your data processing, then getting the distinct count in those tools is a natural choice.

For any other situation, or as part of a larger automated process, the custom VBA or Office Scripts code solutions might be the best.

Did you know any of these methods? Let me know in the comments!

About the Author

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Working with large data sets, we often require the count of unique and distinct values in Excel. Though this may be required in many cases, Excel does not have any pre-defined formula to count unique and distinct values. In this tutorial, you will see a few techniques to count unique and distinct values in Excel.

How to Count Unique and Distinct Values in Excel

The unique values are the ones that appear only once in the list, without any duplications. The distinct values are all the different values in the list.

                                          

In this example, you have a list of numbers ranging from 1-6. The unique values are the ones that appear only once in the list, without any duplications. The distinct values are all the different values in the list. The tables below show the unique and distinct values in this list.

Count unique values in Excel

You can use the combination of the SUM and COUNTIF functions to count unique values in Excel. The syntax for this combined formula is = SUM(IF(1/COUNTIF(data, data)=1,1,0)). Here the COUNTIF formula counts the number of times each value in the range appears.

The resulting array looks like {1;2;1;1;1;1}. In the next step, you divide 1 by the resulting values. The IF function implements the logic such that if the values appear only once in the range, this step will generate 1, otherwise it will be a fraction value. The SUM function then sums all the values and returns the result. This is an array formula, so you have to assign it using Ctrl + Shift + Enter.

The following example contains a list of automobile products with their product ID and Names. You will count the unique items in this example.

{=SUM(IF(1/COUNTIF(A2:A11,A2:A11)=1,1,0))}

This counts the number of unique values in the list. It follows the syntax mentioned above and returns the count for unique items, which is 5.

{=SUM(IF(ISNUMBER(A2:A11)*COUNTIF(A2:A11,A2:A11)=1,1,0))}

This counts the number of unique numeric values in the list. The only difference with the previous formula is here is the nested ISNUMBER formula that makes sure that you only count the numeric values. Returns the number 3, which is the count of the unique numeric values.

{=SUM(IF(ISTEXT(A2:A10)*COUNTIF(A2:A11,A2:A11)=1,1,0))}

Works the same as the previous formula, counts the unique number of text values instead. The ISTEXT function is used to make sure that only the text values are counted. Returns the number 2.

Count Distinct Values in Excel

Count Distinct Values using a Filter

You can extract the distinct values from a list using the Advanced Filter dialog box and use the ROWS function to count the unique values. To count the distinct values from the previous example:

  • Select the range of cells A1:A11.
  • Go to Data > Sort & Filter > Advanced.

  • In the Advanced Filter dialog box, click Copy to another location.
  • Set both List Range and Criteria Range to $A$1:$A$11.
  • Set Copy to to $F$2.
  • Keep the Unique Records Only box checked. Click OK.

  • Column F will now contain the distinct values.
  • Select H6.
  • Enter the formula =ROWS(F3:F9). Click Enter.

This will show the count of distinct values, 7.

Count Distinct Values using Formulas

You can use the combination of the IF, MATCH, LEN and FREQUENCY functions with the SUM function to count distinct values.

{=SUM(IF(A2:A11<>"",1/COUNTIF(A2:A11, A2:A11), 0))}

Counts the number of distinct values between cells A2 to A11. Like the unique count, here the COUNTIF function returns a count for each individual value which is then used as a denominator to divide 1. The returning values are then summed if they are not 0. This gives you a count for the distinct values, regardless of their types.

=SUM(IF(FREQUENCY(MATCH(A2:A11,A2:A11,0),MATCH(A2:A11,A2:A11,0))>0,1))

Does the same thing as the previous formula. The only differences being the use of the FREQUENCY and MATCH functions. The frequency function returns the number of occurrences for a value for the first occurrence. For the next occurrence of that value, it returns 0. The MATCH function is used to return the position of a text value in the range. These are returned as then used as an argument to the FREQUENCY function which gives us a count of the total number of distinct values.

=SUM(IF(FREQUENCY(A2:A11,A2:A11)>0,1))

Counts the number of distinct numeric values. As the FREQUENCY function ignores text and blanks, it returns 5, which is the number of numeric values.

{=SUM(IF(ISTEXT(A2:A11),1/COUNTIF(A2:A11, A2:A11),""))}

Returns the count of distinct text values in a range. Like the first example, this counts the distinct values, but the ISTEXT function makes sure only the text values are taken into count.

Count Distinct Values using a Pivot Table

You can also count distinct values in Excel using a pivot table. To find the distinct count of the bike names from the previous example:

To count the distinct items using a pivot table:

  • Select cells A1:B11. Go to Insert > Pivot Table.
  • In the dialog box that pops up, check New Worksheet and Add this to the Data Model.

  • Drag the Product ID field to Rows, Names field to Values in the PivotTable Fields.

  • Right-click on any value in column B. Go to Value Field Settings. In the Summarize Values By tab, go to Summarize Value field by and set it to Distinct Count.

This will show the distinct count 7 in cell B11.

Still need some help with Excel formatting or have other questions about Excel? Connect with a live Excel expert here for some 1 on 1 help. Your first session is always free. 

Excel Pivot Tables are amazing (I know I mention this every time I write about Pivot Tables, but it’s true).

With a basic understanding and a little drag and drop, you can get a bucket-load of work done in a few seconds.

While a lot can be done with a few clicks in Pivot Tables, there are some things that would need a few extra steps or a little bit of work around.

And one such thing is to count distinct values in a Pivot Table.

In this tutorial, I will show you how to count distinct values as well as Unique Values in an Excel Pivot table.

But before I jump into how to count distinct values, it’s important to understand the difference between ‘distinct count’ and ‘unique count’

Distinct Count Vs Unique Count

While these may seem like the same thing, it’s not.

Below is an example where there is a dataset of names and I have listed unique and distinct names separately.

Difference between unique count and distinct count

Unique values/names are those that only occur once. This means that all the names that repeat and have duplicates are not unique. Unique names are listed in column C in the above dataset

Distinct values/names are those that occur at least once in the dataset. So if a name appears three times, it’s still counted as one distinct name. This can be achieved by removing the duplicate values/names and keeping all the distinct ones. Distinct names are listed in column B in the above data set.

Based on what I have seen, most of the times when people say that they want to get the unique count in a Pivot Table, they actually mean distinct count, which is what I am covering in this tutorial.

Count Distinct Values in Excel Pivot Table

Suppose you have the sales data as shown below:

Pivot Table Data from which distinct values need to be counted

Click here to download the example file and follow along

With the above dataset, let’s say that you want to find the answer to the following questions:

  1. How many sales rep are there in each region (which is nothing but the distinct count of sales reps in each region)?
  2. How many sales rep sold the printer in 2020?

While Pivot Tables can instantly summarize the data with a few clicks, to get the count of distinct values, you will need to take a few more steps.

If you’re using Excel 2013 or versions after that, there is an inbuilt functionality in Pivot Table that quickly gives you the distinct count. And if you’re using Excel 2010 or versions before that, you will have to modify the source data by adding a helper column.

The following two methods are covered in this tutorial:

  • Adding a helper column in the original data set to count unique values (works in all versions).
  • Adding the data to a data model and using Distinct Count option (available in Excel 2013 and versions after that).

There is a third method which Roger shows in this article (which he calls the Pivot the Pivot Table method).

Let’s get started!

Adding a Helper Column in the Dataset

Note: If you’re using Excel 2013 and higher versions, skip this method and move to the next one (as it uses an inbuilt Pivot Table functionality – Distinct Count).

This is an easy way to count distinct values in the Pivot Table as you only need to add a helper column to the source data. Once you have added a helper column, you can then use this new data set to calculate the distinct count.

While this is an easy workaround, there are some drawbacks to this method (covered later in this tutorial).

Let me first show you how to add a helper column and get a distinct count.

Suppose I have the data set as shown below:

Pivot Table Data from which distinct values need to be counted

Add the following formula in Column F and apply it for all the cells that have data in the adjacent columns.

=IF(COUNTIFS($C$2:C2,C2,$B$2:B2,B2)>1,0,1)

The above formula uses the COUNTIFS function to count the number of times a name appears in the given region. Also, note that the criteria range is $C$2:C2 and $B$2:B2. This means that it keeps expanding as you go down the column.

For example, in cell E2, the criteria ranges are $C$2:C2 and $B$2:B2 and in cell E3 these ranges expand to $C$2:C3 and $B$2:B3.

This ensures that the COUNTIFS function counts the first instance of a name as 1, the second instance of the name as 2, and so on.

Since we only want to get the distinct names, the IF function is used which returns 1 when a name appears for a region the first time and returns 0 when it appears again. This makes sure that only distinct names are counted and not the repeats.

Below is how your dataset would look like when you have added the helper column.

Distinct Count Helper Column in Pivot Table Data

Now that we have modified the source data, we can use this to create a Pivot Table and use the helper column to get the distinct count of the sales rep in each region.

Below are the steps to do this:

  1. Select any cell in the dataset.
  2. Click the Insert Tab.Click the Insert Tab
  3. Click on Pivot Table (or use the keyboard shortcut – ALT + N + V)Click on Pivot Table option
  4. In the Create Pivot Table dialog box, make sure that the Table/Range is correct (and includes the helper column) and’New Worksheet’ in selected.Create Pivot Table Dialog box
  5. Click OK.

The above steps would insert a new sheet which has the Pivot Table.

Drag the ‘Region’ field in the Rows area and ‘D Count’ field in the Values area.

Pivot table Areas to get distinct count

You will get a Pivot Table as shown below:

Pivot Table with sum of distinct count

Now you can change the column header from ‘Sum of D count’ to ‘Sales Rep’.

Drawbacks of Using a Helper Column:

While this method is pretty straight forward, I must highlight a few drawbacks that come with modifying the source data in a Pivot Table:

  • The data source with the helper column is not as dynamic as a Pivot Table. While you can slice and dice the data any way you want with a Pivot Table, when you use a helper column, you lose a part of that ability. Let’s say that you add a helper column to get the count of a distinct sales rep in each region. Now, what if you also want to get the distinct count of sales rep selling printers. You will have to go back to the source data and modify the helper column formula (or add a new helper column).
  • Since you’re adding more data to the Pivot Table source (which also gets added to the Pivot Cache), this can lead to a higher size of Excel file.
  • Since we are using an Excel formula, it may make your Excel Workbook slow in case you have thousands of rows of data.

Add Data to Data Model and Summarize Using Distinct Count

Pivot Table added new functionality in Excel 2013 that allows you to get the distinct count while summarizing the data set.

In case you’re using a previous version, you’ll not be able to use this method (as should try adding the helper column as shown in the method above this one).

Suppose you have a dataset as shown below and you want to get the count of the unique sales rep in each region.

Excel Pivot Table Data Set

Below are the steps to get a distinct count value in the Pivot Table:

  1. Select any cell in the dataset.
  2. Click the Insert Tab.Click the Insert Tab
  3. Click on Pivot Table (or use the keyboard shortcut – ALT + N + V)Click on Pivot Table option
  4. In the Create Pivot Table dialog box, make sure that the Table/Range is correct and New Worksheet in Selected.
  5. Check the box which says – “Add this data to the Data Model”Create PivotTable Dialog Box - Check Add Data to Data Model
  6. Click OK.

The above steps would insert a new sheet which has the new Pivot Table.

Drag the Region in the Rows area and Sales Rep in the Values area. You will get a Pivot Table as shown below:

Pivot Table created with data model

The above Pivot Table gives the total count of the Sales rep in each region (and not the distinct count).

To get the distinct count in the Pivot Table, follow the below steps:

  1. Right-click on any cell in the ‘Count of Sales Rep’ column.
  2. Click on Value Field SettingsClick on Value Field Settings
  3. In the Value Field Settings dialog box, select ‘Distinct Count’ as the type of calculation (you may have to scroll down the list to find it).Click on Distinct Count in Value Field Setting Dialog Box
  4. Click OK.

You will notice that the name of the column changes from ‘Count of Sales Rep’ to ‘Distinct Count of Sales Rep’. You can change it to whatever you want.

Distinct Count of Sales Rep

Some things you know when you add your data to the Data Model:

  • If you save your data in the data model and then open in an older version of Excel, it will show you a warning – ‘Some pivot table functions will not be saved’. You may not see the distinct count (and the data model) when opened in an older version that doesn’t support it.
  • When you add your data to a Data Model and make a Pivot Table, it will not show the options to add calculated fields and calculated columns.

Click here to download the example file

What If You Want to Count Unique Values (and not distinct values)?

If you want to count unique values, you don’t have any inbuilt functionality in the Pivot Table and will have to rely on helper columns only.

Remember – Unique values and distinct values are not the same. Click here to know the difference.

One example could be when you have the below data set and you want to find out how many sales rep are unique to each region. This means that they operate in one specific region only and not the others.

In such cases, you need to create one of more than one helper columns.

For this case, the below formula does the trick:

=IF(IF(COUNTIFS($C$2:$C$1001,C2,$B$2:$B$1001,B2)/COUNTIF($C$2:$C$1001,C2)<1,0,1),IF(COUNTIF($C2:C$22,C2)>1,0,1),0)

The above formula checks whether a sales rep name occurs in one region only or in more than one region. It does that by counting the number of occurrence of a name in a region and dividing it by the total number of occurrences of the name. If the value is less than 1, it indicates that the name occurs in two or more than two regions.

In case the name occurs in more than one region, it returns a 0 else it returns a one.

The formula also checks whether the name is repeated in the same region or not. If the name is repeated, only the first instance of the name returns the value 1, and all other instances return 0.

This may seem a bit complex, but it again depends on what you’re trying to achieve.

So, if you want to count unique values in a Pivot Table, use helper columns and if you want to count distinct values, you can use the inbuilt functionality (in Excel 2013 and above) or can use a helper column.

Click here to download the example file

You May Also Like the Following Pivot Table Tutorials:

  • How to Filter Data in a Pivot Table in Excel
  • How to Group Dates in Pivot Tables in Excel
  • How to Group Numbers in Pivot Table in Excel
  • How to Apply Conditional Formatting in a Pivot Table in Excel
  • Slicers in Excel Pivot Table
  • How to Refresh Pivot Table in Excel
  • Delete a Pivot Table in Excel

Содержание

  1. Counting Unique Values In Excel – 5 Effective Ways
  2. Method – 1: Using SumProduct and CountIF Formula:
  3. Let’s See How This Formula Works:
  4. The Catch:
  5. Method – 2: Using SUM, FREQUENCY AND MATCH Array Formula
  6. Let’s Try To Understand How This Formula Works:
  7. Method – 3: Using PivotTable (Only works in Excel 2013 and above)
  8. Method – 4: Using SUM and COUNTIF function
  9. Let’s See How This Formula Works:
  10. Method 5 – COUNTUNIQUE User Defined Function:
  11. How to Use the UDF:
  12. Subscribe and be a part of our 15,000+ member family!
  13. Distinct Count
  14. Count Distinct in Excel 2010
  15. Watch Video
  16. Video Transcript

Counting Unique Values In Excel – 5 Effective Ways

Let’s consider we have a long list of duplicate values in a range and our objective is to count only the unique occurrences of each value.

Though this can be a very common requirement in many scenarios but excel doesn’t have any single formula that can directly help us to count unique values in excel inside a range.

In today’s post, we will see 5 different ways of counting unique values in excel.

But, before starting let’s make our goal clear.

By looking at the above image, we can clearly see that what we mean by counting unique value in excel.

Table of Contents

Method – 1: Using SumProduct and CountIF Formula:

The simplest and easiest way to count distinct values in excel is to use SumProduct and CountIF formula.

Following is the generic formula that you can use:

‘data’ – data represents the range that contains the values

Let’s See How This Formula Works:

This formula consists of two functions combined together. Let’s first understand the role of inner CountIF function.

The CountIF function looks inside the data range (B2:B9) and counts the number of times each value appears in data range.

The result is an array of numbers and in our example it might look something like this: <2;2;3;3;3;2;2;1>.

Next, the results of CountIF formula are used as a divisor with 1 as numerator. This modifies the result of CountIF formula such that; values that only appear once in the array become 1 and the numbers corresponding to duplicate values become fractions corresponding to the multiple.

This means that, if a value appears 4 times in the range then its value will become as 1/4 = 0.25 and value that is present only once will become 1/1 = 1

Finally, the SumProduct formula adds up all the elements in the array and returns the final result.

Read these articles for more details on CountIF Function or SumProduct Function.

The Catch:

This formula woks nicely on a continuous set of values in a range, however if your values contain empty cells, then this formula fails. In such cases the formula throws a ‘divide by zero’ error.

Because, CountIF function generates a ‘0’ for each blank cell and when 1 is divided by 0 it returns a divide by zero error.

To fix this, you can use the following variant of the above formula that ignores the blank cells:

‘data’ – data represents the range that contains the values

Method – 2: Using SUM, FREQUENCY AND MATCH Array Formula

The formula that we discussed above is good to be used for small ranges. As the range becomes bigger the SUMPRODUCT and COUNTIF formula will become slower and will eventually make your spreadsheets unresponsive while counting unique values inside a range.

So, for larger datasets, you may want to switch to a formula based on the FREQUENCY function.

The generic formula is as follows:

Here, ‘data’ represents the range that contains the values.

And ‘firstcell’ represents the first cell of the range.

Note: This is an array formula so, after writing the formula press ‘Control-Shift-Enter’ and the formula will get surrounded by curly braces as shown below.

Let’s Try To Understand How This Formula Works:

This formula uses Frequency function to count the unique values, but the problem here is that FREQUENCY function is only designed to work with numbers. So, here our first objective is to convert the values into a set of numbers.

Starting from inside, the MATCH function in this formula gives us the first occurrence or position number of each item that appears in the data range. If there are any values that are duplicate, then MATCH will return only the position of the first occurrence of that value in the data range.

After the MATCH function, there is an IF Statement. The reason IF function is required because MATCH will return a #N/A error for empty cells. So, we are excluding the empty cells with data <> «» .

The resulting array contains a set of numbers combined with False for the blank cells. So, in our case the resulting array would be like:

This array is fed to the FREQUENCY function which returns how often values occur within the set of data and finally the outer IF function sets each unique value to 1 and duplicate value to FALSE.

And the final result comes out to be 4.

Method – 3: Using PivotTable (Only works in Excel 2013 and above)

The integration of power pivot with excel (known as Data Model), has provided some powerful features to the users. Now pivot tables can also help you to get the distinct counts of unique values in excel.

To do this follow the below steps:

  1. Navigate to the ‘Insert’ option on the top ribbon and click the ‘PivotTable’ option.

  1. This will open a ‘PivotTable’ dialog, select the data range and check the checkbox that says ‘Add this data to Data Model’ and finally click ‘Ok’ button.

  1. Build the PivotTable by placing the column that contains data range ‘Values’ and in the ‘Rows’ quadrant as shown below.

  1. Doing this will show the total count including the duplicate values, however we only need to get the count of distinct values. So, right click over the Count column and select the ‘Value Field Settings’ option.

  1. Next, In the ‘Value Field Settings’ window, select the ‘Distinct Count’ option and click ‘Ok’ button.

  1. Doing this will fetch the distinct counts for the values and populate them in the PivotTable.

Method – 4: Using SUM and COUNTIF function

This is again an array formula to count distinct values in a range.

Here, ‘range’ represents the range that contains the values.

Note: This is an array formula so, after writing the formula press ‘Control-Shift-Enter’ and the formula will get surrounded by curly braces as shown below.

Let’s See How This Formula Works:

In this formula, we have used ISTEXT function. ISTEXT function returns a true for all the values that are text and false for other values.

If the value is a text value, then the COUNTIF function executes and looks inside the data range (B2:B9) and counts the number of times that each value appears in data range.

After this, the result of CountIF function are used as a divisor with 1 as the numerator (same as in first method). This means that, if a value appears 4 times in the range its value will become as 1/4 = 0.25 and when the value is present only once then it becomes 1/1 = 1

Finally, the SUM function computes the sum of all the values and returns the result.

Method 5 – COUNTUNIQUE User Defined Function:

If none of the above options work for you, then you can create your own user defined function (UDF) that can count unique values in excel for you.

Below is the code to write your own UDF that does the same:

To embed this function in Excel use the following steps:

  1. Press Alt + F11 key on the Excel, this will open the VBA window.
  2. On the VBA Window, right click over the ‘Microsoft Excel Objects’ > ‘Insert’ > ‘Module’.

  1. Clicking the ‘Module’ will open a new module in the Excel. Paste the UDF code in the module window as shown below.

  1. Finally, save your spreadsheet and the formula is ready to use.

How to Use the UDF:

To use the UDF, you can simply type the UDF name ‘ CountUnique ’ like a normal excel function.

‘data_range’ – represents the range that contains the values.

‘count_blanks’ – is a boolean parameter that can have two values true or false. If you set this parameter as true then it will count the blank rows as unique. By setting this parameter to false the UDF will exclude the blank rows.

So, these were all the methods that can help you to count unique value in excel. Do let us know your own methods or tricks to do the same.

Subscribe and be a part of our 15,000+ member family!

Now subscribe to Excel Trick and get a free copy of our ebook «200+ Excel Shortcuts» (printable format) to catapult your productivity.

Источник

Distinct Count

August 30, 2017 — by Bill Jelen

Excel Distinct Count or Unique Count. Pivot tables will offer a distinct count, if you check one tiny box as you create the pivot table.

Here is an annoyance with pivot tables. Drag the Customer column from the Data table to the VALUES area. The field says Count of Customer, but it is really a count of how many invoices belong to each sector. What if you really want to see how many unique customers belong to each sector?

Pivot Table

Select a cell in the Count of Customer column. Click Field Settings. At first, the Summarize Values By looks like the same Sum, Average, and Count that you’ve always had. But scroll down to the bottom. Because the pivot table is based on the Data Model, you now have Distinct Count.

After you select Distinct Count, the pivot table shows a distinct count of customers for each sector. This was very hard to do in regular pivot tables.

The Result

Count Distinct in Excel 2010

To join two tables in Excel 2010, you have to download the free Power Pivot add-in from Microsoft. Once you have that installed, here are the extra steps to get your data into Power Pivot:

  1. Select a cell in the Data table. On the PowerPivot tab, choose Create Linked Table. If Excel leaves you in the PowerPivot grid, use Alt + Tab to get back to Excel.
  2. Select a cell in the Sectors table. Choose Create Linked Table.
  3. From either the PowerPivot tab in the Excel ribbon or the Home tab in the PowerPivot ribbon, choose to create a pivot table.

When it comes time to create relationships, you have only one button called Create. Excel 2010 will attempt to AutoDetect relationships first. In this simple example, it will get the relationship correct.

Thanks to Colin Michael and Alejandro Quiceno for suggesting Power Pivot in general.

Watch Video

  • Introduced the Data Model in Podcast 2014 for Joining Tables
  • Another Benefit is the ability to do Distinct Count
  • Regular pivot table can not count customers per sector
  • Add the data to the Data Model and you have Distinct Count available
  • Before Excel 2013, you would have to add 1 / COUNTIF to the original data

Video Transcript

Learn Excel from MrExcel podcast, episode 2015 — Distinct Count!

Alright, all the tips in this book are going to be podcast, check out this playlist for the whole set!

OK, so today we have to create a report that shows how many customers are in each sector, and a regular Pivot table CANNOT do this. So Insert PivotTable will put sectors down the left-hand side, and then ask for the count of Customer, and it says it’s giving us the count of Customer. But this isn’t the count of Customer, this is how many records there are, alright, we don’t have 563 customers, completely, completely useless. But check this out, amazingly easy to solve this, yesterday’s podcast we talked about using the Data Model to join 2 tables together. Today I just have one table, there’s, you know, you wouldn’t think there’s any reason to use the data model, except for this, so choose the box “Add this data to the Data Model”.

By the way, this is brand new in Excel 2013, so you need 13 or 16, if you’re stuck on a Mac or back in Excel 2010, I’ll show you the old solution here at the end. Click OK, build the exact same report, sectors down the left-hand side, count of Customer, an exact same wrong answer, but here’s the difference. When we come into Field Settings see, it looks the same, Sum, Count, Average, Max, Min, there’s a few missing, and at the very bottom there’s a new one called Distinct Count. Wow, that is something that has been so hard to do in old versions of Excel, in fact let me show you how we used to do it in Excel 2010.

So here’s the data, you would have to come out and do a COUNTIF, count how many times Vertex42 appears in column D, and it appears there are 6 times. So then the Distinct Count is =1 divided by that, alright, see what we’re doing, if there’s six records with Vertex42, we’re giving each of them 1/6 or 0.16611, and when we add all that up, that will get us to 1, right? There’s 5 records here, each gets 1/5 or 20%, add all those up, each of those gets us to 1. So back in Excel 2010 or 7 or 3 or wherever you are, you don’t have the Data Model, so you add those extra fields there, Sector, and then Distinct Count. This was so much more difficult than the new way, so I certainly appreciate the data model for this one. Well this tip, and a lot more in the book, click the “i” on the top-right hand corner, you can buy the book, $25 in print, $10 for an e-book, it’s cheap!

In yesterday’s podcast, 2014, we talked about the Data Model for joining tables, another benefit is the ability to do a distinct count. Regular Pivot table cannot count customers per sector, add the data to the Data Model, and you have Distinct Count available. Before Excel 2013, you do 1/COUNTIF in the original data, and of course, if you want to do distinct count for something else, you might have to change that formula, really, really frustrating. Beautiful, beautiful side benefit of the whole Power Pivot engine!

Download the sample file here: Podcast2015.xlsx

Источник

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 including Office 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. 

Example of how to count unique and distinct values in Excel
How to count unique and distinct values in Excel

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.

Example for unique and distinct values in Excel
Example for unique and distinct values in Excel

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.

Enter the SUM, IF and COUNTIF functions in the desired cell
Enter the SUM, IF and COUNTIF functions in the desired cell

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.

Select advanced from filter menu
Select advanced from filter menu

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 , 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.

Specify the range and click OK
Specify the range and click OK

Thus the distinct elements are copied onto a new row. 

Distinct elements copied onto new row
Distinct elements copied onto new row

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. 

Row count the distinct elements
Row count the distinct elements

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

Enter formula to find the row count
Enter formula to find the row count

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.

Enter the SUM and COUNTIF function in the desired cell
Enter the SUM and COUNTIF function in the desired cell

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. 

Enter the SUMPRODUCT and COUNTIF function in the desired cell

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

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!

Let’s consider we have a long list of duplicate values in a range and our objective is to count only the unique occurrences of each value.

Though this can be a very common requirement in many scenarios but excel doesn’t have any single formula that can directly help us to count unique values in excel inside a range.

In today’s post, we will see 5 different ways of counting unique values in excel.

But, before starting let’s make our goal clear.

Count_Uniques_Image_1

By looking at the above image, we can clearly see that what we mean by counting unique value in excel.

Method – 1: Using SumProduct and CountIF Formula:

The simplest and easiest way to count distinct values in excel is to use SumProduct and CountIF formula.

Following is the generic formula that you can use:

=SUMPRODUCT(1/COUNTIF(data,data))

‘data’ – data represents the range that contains the values

Count_Uniques_Image_2

Let’s See How This Formula Works:

This formula consists of two functions combined together. Let’s first understand the role of inner CountIF function.

The CountIF function looks inside the data range (B2:B9) and counts the number of times each value appears in data range.

The result is an array of numbers and in our example it might look something like this: {2;2;3;3;3;2;2;1}.

Next, the results of CountIF formula are used as a divisor with 1 as numerator. This modifies the result of CountIF formula such that; values that only appear once in the array become 1 and the numbers corresponding to duplicate values become fractions corresponding to the multiple.

This means that, if a value appears 4 times in the range then its value will become as 1/4 = 0.25 and value that is present only once will become 1/1 = 1

Finally, the SumProduct formula adds up all the elements in the array and returns the final result.

Read these articles for more details on CountIF Function or SumProduct Function.

The Catch:

This formula woks nicely on a continuous set of values in a range, however if your values contain empty cells, then this formula fails. In such cases the formula throws a ‘divide by zero’ error.

Because, CountIF function generates a ‘0’ for each blank cell and when 1 is divided by 0 it returns a divide by zero error.

Count_Uniques_Image_3

To fix this, you can use the following variant of the above formula that ignores the blank cells:

=SUMPRODUCT(((data<>"")/COUNTIF(data , data &"")))

‘data’ – data represents the range that contains the values

Count_Uniques_Image_4

Method – 2: Using SUM, FREQUENCY AND MATCH Array Formula

The formula that we discussed above is good to be used for small ranges. As the range becomes bigger the SUMPRODUCT and COUNTIF formula will become slower and will eventually make your spreadsheets unresponsive while counting unique values inside a range.

So, for larger datasets, you may want to switch to a formula based on the FREQUENCY function.

The generic formula is as follows:

=SUM(IF(FREQUENCY(IF(data<>"", MATCH(data,data,0)),ROW(data)-ROW(firstcell)+1),1))

Here, ‘data’ represents the range that contains the values.

And ‘firstcell’ represents the first cell of the range.

Note: This is an array formula so, after writing the formula press ‘Control-Shift-Enter’ and the formula will get surrounded by curly braces as shown below.

Count_Uniques_Image_5

Let’s Try To Understand How This Formula Works:

This formula uses Frequency function to count the unique values, but the problem here is that FREQUENCY function is only designed to work with numbers. So, here our first objective is to convert the values into a set of numbers.

Starting from inside, the MATCH function in this formula gives us the first occurrence or position number of each item that appears in the data range. If there are any values that are duplicate, then MATCH will return only the position of the first occurrence of that value in the data range.

After the MATCH function, there is an IF Statement. The reason IF function is required because MATCH will return a #N/A error for empty cells. So, we are excluding the empty cells with data <> "".

The resulting array contains a set of numbers combined with False for the blank cells. So, in our case the resulting array would be like:

{1;1;3;3;3;6;FALSE;6;9}

This array is fed to the FREQUENCY function which returns how often values occur within the set of data and finally the outer IF function sets each unique value to 1 and duplicate value to FALSE.

And the final result comes out to be 4.

Method – 3: Using PivotTable (Only works in Excel 2013 and above)

The integration of power pivot with excel (known as Data Model), has provided some powerful features to the users. Now pivot tables can also help you to get the distinct counts of unique values in excel.

To do this follow the below steps:

  1. Navigate to the ‘Insert’ option on the top ribbon and click the ‘PivotTable’ option.

Count_Uniques_Image_6

  1. This will open a ‘PivotTable’ dialog, select the data range and check the checkbox that says ‘Add this data to Data Model’ and finally click ‘Ok’ button.

Count_Uniques_Image_7

  1. Build the PivotTable by placing the column that contains data range ‘Values’ and in the ‘Rows’ quadrant as shown below.

Count_Uniques_Image_8

  1. Doing this will show the total count including the duplicate values, however we only need to get the count of distinct values. So, right click over the Count column and select the ‘Value Field Settings’ option.

Count_Uniques_Image_9

  1. Next, In the ‘Value Field Settings’ window, select the ‘Distinct Count’ option and click ‘Ok’ button.

Count_Uniques_Image_10

  1. Doing this will fetch the distinct counts for the values and populate them in the PivotTable.

Count_Uniques_Image_11

Method – 4: Using SUM and COUNTIF function

This is again an array formula to count distinct values in a range.

=SUM(IF(ISTEXT(range),1/COUNTIF(range, range), ""))

Here, ‘range’ represents the range that contains the values.

Note: This is an array formula so, after writing the formula press ‘Control-Shift-Enter’ and the formula will get surrounded by curly braces as shown below.

Count_Uniques_Image_12

Let’s See How This Formula Works:

In this formula, we have used ISTEXT function. ISTEXT function returns a true for all the values that are text and false for other values.

If the value is a text value, then the COUNTIF function executes and looks inside the data range (B2:B9) and counts the number of times that each value appears in data range.

After this, the result of CountIF function are used as a divisor with 1 as the numerator (same as in first method). This means that, if a value appears 4 times in the range its value will become as 1/4 = 0.25 and when the value is present only once then it becomes 1/1 = 1

Finally, the SUM function computes the sum of all the values and returns the result.

Method 5 – COUNTUNIQUE User Defined Function:

If none of the above options work for you, then you can create your own user defined function (UDF) that can count unique values in excel for you.

Below is the code to write your own UDF that does the same:

Function COUNTUNIQUE(DataRange As Range, CountBlanks As Boolean) As Integer
Dim CellContent As Variant
Dim UniqueValues As New Collection
Application.Volatile
On Error Resume Next
For Each CellContent In DataRange
If CountBlanks = True Or IsEmpty(CellContent) = False Then
UniqueValues.Add CellContent, CStr(CellContent)
End If
Next
COUNTUNIQUE = UniqueValues.Count
End Function

To embed this function in Excel use the following steps:

  1. Press Alt + F11 key on the Excel, this will open the VBA window.
  2. On the VBA Window, right click over the ‘Microsoft Excel Objects’ > ‘Insert’ > ‘Module’.

Count_Uniques_Image_13

  1. Clicking the ‘Module’ will open a new module in the Excel. Paste the UDF code in the module window as shown below.

Count_Uniques_Image_14

  1. Finally, save your spreadsheet and the formula is ready to use.

How to Use the UDF:

To use the UDF, you can simply type the UDF name ‘CountUnique’ like a normal excel function.

=COUNTUNIQUE(data_range, count_blanks)

‘data_range’ – represents the range that contains the values.

‘count_blanks’ – is a boolean parameter that can have two values true or false. If you set this parameter as true then it will count the blank rows as unique. By setting this parameter to false the UDF will exclude the blank rows.

Count_Uniques_Image_15

So, these were all the methods that can help you to count unique value in excel. Do let us know your own methods or tricks to do the same.

Counting Unique Values in Excel

Unique value in excel appears in a list of items only once and the formula for counting unique values in Excel is “=SUM(IF(COUNTIF(range,range)=1,1,0))”. The purpose of counting unique and distinct values is to separate them from the duplicates of a list of Excel.

A duplicate value appears in a list of items more than once. A distinct value refers to all the different values of the list of items. So, distinct values are unique values plus the first occurrences of duplicate values.

For example, a list contains the numbers 10, 12, 15, 15, 18, 18, and 19. The unique values of this list are 10, 12, and 19. The duplicate values are 15 and 18. The distinct values are 10, 12, 15, 18, and 19.

This article focuses on counting the distinct values of Excel. For counting the unique values of Excel, refer to the first question under the heading “frequently asked questions” of this article.

Table of contents
  • Counting Unique Values in Excel
    • How to Count the Distinct Values in Excel?
      • Example #1–Count Unique Excel Values by Using the SUM and COUNTIF Functions
      • Example #2–Count Unique Excel Values by Using the SUMPRODUCT and COUNTIF Functions
      • Example #3–Count Unique Excel Values by Excluding the Empty Cells of the Range
    • Frequently Asked Questions
    • Recommended Articles

How to Count the Distinct Values in Excel?

The methods of counting the distinct values in Excel are listed as follows:

  1. SUM and COUNTIF functions
  2. SUMPRODUCT and COUNTIF functions

Let us discuss the two methods with the help of examples.

You can download this COUNT Unique Values Excel Template here – COUNT Unique Values Excel Template

Example #1–Count Unique Excel Values by Using the SUM and COUNTIF Functions

The following image shows the names of customers (column A) and the dates (column B) on which sales were made to them. The revenue generated (in $) from each customer is given in column C.

The entire dataset belongs to an organization. It relates to the period April 2018. Count the unique values of excel column A with the help of the SUM and COUNTIF functions of Excel.

Count Unique Values in Excel Step 1

The steps to count the unique excel values by using the SUMThe SUM function in excel adds the numerical values in a range of cells. Being categorized under the Math and Trigonometry function, it is entered by typing “=SUM” followed by the values to be summed. The values supplied to the function can be numbers, cell references or ranges.read more and COUNTIFThe COUNTIF function in Excel counts the number of cells within a range based on pre-defined criteria. It is used to count cells that include dates, numbers, or text. For example, COUNTIF(A1:A10,”Trump”) will count the number of cells within the range A1:A10 that contain the text “Trump”
read more
functions of Excel are listed as follows:

Step 1: Enter the following formula in cell E3.

Using SUM and COUNTIF formula 1-2

Step 2: Press the keys “Ctrl+Shift+Enter” together. This is because the given formula is an array formulaArray formulas are extremely helpful and powerful formulas that are used in Excel to execute some of the most complex calculations. There are two types of array formulas: one that returns a single result and the other that returns multiple results.read more. On pressing the CSE (Ctrl+Shift+EnterCtrl-Shift Enter In Excel is a shortcut command that facilitates implementing the array formula in the excel function to execute an intricate computation of the given data. Altogether it transforms a particular data into an array format in excel with multiple data values for this purpose.read more) keys, the curly braces appear at the beginning and end of the formula, as shown in the following image.

Note: An array formula is always completed by pressing the CSE keys. Even after editing an array formula, the CSE keys must be pressed to save the changes made. An array formula cannot be applied to merged cells.

Using SUM and COUNTIF formula 1

Step 3: Once the CSE keys are pressed, the output appears in cell E3. This is shown in the following image. Hence, there are 12 distinct values in column A. In other words, the organization sold to 12 different customers in April 2018.

Count Unique Values in Excel Step 2

Explanation of the formula: The formula entered in step 1 has three parts, namely, the COUNTIF function, “1/,” and the SUM function. These are shown in the following image.

Ignore the arrows of parts 2 and 1, which are slightly misplaced in the following image.

Using SUM and COUNTIF formula 1-1

In this formula, the COUNTIF function is processed first as it is the innermost function. Thereafter, “1/” and the SUM function are processed. The entire formula works as follows:

a. The COUNTIF function is supplied a single range (A2:A25) twice. This tells the function to count the number of times a value appears in this range. Since there are 24 values in this range, the COUNTIF function returns an array of 24 values. These are shown in the following image.

Using SUM and COUNTIF formula 1-3

So, the first 3 implies that the name “Ruturaj” appears thrice in the range A2:A25. Likewise, the following 1 implies that the name “Kamal” appears once in this range.

b. Next, the number 1 is divided by all the values returned in the preceding array. The output is again an array of 24 values. These are shown in the following image.

Using SUM and COUNTIF formula 1-4

Since “Ruturaj” appears thrice (in A2:A25), the value 3 divided by 1 returns 0.33. Likewise, “Kamal” appears once, so 1 divided by 1 is equal to 1. Therefore, all values that appear once in the stated range (A2:A25) return 1. The values that return a decimal number have more than one occurrence.

c. Then, the SUM function sums the values returned in the preceding array. Note that if a value appears thrice in the stated range, 0.33 (1/3=0.33) appears thrice. So, 0.33+0.33+0.33 is equal to 1. Likewise, if a value appears twice in the range A2:A25, 0.5 (1/2=0.5) appears twice. So, 0.5+0.5 is equal to 1. In this way, the sum of all occurrences of a value is always equal to 1. Therefore, the SUM function returns the total of all the different values in the range A2:A25.

Hence, the count of unique excel values (in the range A2:A25) is 12. This 12 is the sum of two unique values (Kamal and Raju) and the first occurrence of ten duplicate values (Ruturaj, Rohit Gulia, Abhishek Tanwar, Srinidhi, Karuna Jain, Andrew Flint, Cummins, Rahul, Ramesh, and Christoper).

Note: To view the array of values returned by the COUNTIF function in pointer “a,” follow the listed steps:

  • Select cell E3 containing the formula.
  • Double-click within the selected cell or press the key F2. This helps enter the Edit mode.
  • Select the COUNTIF part of the formula, i.e., “COUNTIF(A2:A25,A2:A25).”
  • Press the key F9.

Likewise, to view the array of pointer “b,” select cell E3 and double click within the selected cell. Next, select the part “1/COUNTIF(A2:A25,A2:A25)” and press F9.

To exit the Edit mode, press the escape (Esc) key.

Example #2–Count Unique Excel Values by Using the SUMPRODUCT and COUNTIF Functions

The following image shows the dataset of example #1. Count the distinct values of column A with the help of the SUMPRODUCT and the COUNTIF functions of Excel.

Count Unique Values in Excel step 1

The steps to count the distinct values by using the SUMPRODUCTThe SUMPRODUCT excel function multiplies the numbers of two or more arrays and sums up the resulting products.read more and COUNTIF functions are listed as follows:

Step 1: Enter the following formula in cell E6.

Using SUMPRODUCT and COUNTIF formula 1

Step 2: Press the “Enter” key. The output appears in cell E6, as shown in the following image. So, there are 12 distinct values in the range A2:A25.

Notice that the output of the SUM and COUNTIF (example #1) is the same as that of the SUMPRODUCT and COUNTIF (example #2). Hence, since the outputs are the same, one can choose either of the two formulas based on convenience.

Count Unique Values in Excel step 2

Explanation of the formula: The formula given in step 1 (of this example) works exactly the same way the formula of example #1 works. The only difference between the formulas of examples #1 and #2 is the usage of the CSE keys in the former and the usage of the “Enter” key in the latter.

In the current formula, the COUNTIF function and the division by 1 return the same array as that of pointers “a” and “b” of example #1. Being a single array, the SUMPRODUCT sums the values of this array. The output is 12. So, this 12 consists of two unique values and the first occurrences of ten duplicate values.

Note 1: For the detailed working of the current formula, refer to the “explanation of the formula” given at the end of example #1.

Note 2: To see the complete array values returned by the COUNTIF and “1/” part, one can select these parts and press the F9 key. For more details, refer to the note at the end of example #1.

Example #3–Count Unique Excel Values by Excluding the Empty Cells of the Range

Working on the dataset of example #1, we have inserted row 10 as a blank row. As a result, the formulas of examples #1 and #2 show a “#DIV/0!” errorErrors in excel are common and often occur at times of applying formulas. The list of nine most common excel errors are — #DIV/0, #N/A, #NAME?, #NULL!, #NUM!, #REF!, #VALUE!, #####, Circular Reference.read more in cells E3 and E6. This error is displayed when a number is divided by zero (or an empty cell) in Excel.

Count the number of distinct values of column A by excluding the empty cell A10. Use the following functions of Excel:

  • SUM and COUNTIF functions
  • SUMPRODUCT and COUNTIF functions

Handling Blanks 1

The steps to count the distinct values by excluding the empty cell are listed as follows:

Step 1: Enter the following formulas (without the beginning and ending double quotation marks) in cells E3 and E6 respectively.

“=SUM(1/COUNTIF(A2:A26,A2:A26&“”))-1”

“=SUMPRODUCT(1/COUNTIF(A2:A26,A2:A26&“”))-1”

Step 2: Press the CSE keys (Ctrl+Shift+Enter) after entering the SUM and COUNTIF formula. Press the “Enter” key after entering the SUMPRODUCT and COUNTIF formula.

The outputs of both the formulas are shown in the following image. Notice that in this image, the SUM and COUNTIF formula is displayed (in curly braces) in the formula bar.

Hence, the output of both formulas is 12. This implies that there are 12 distinct values in column A. The empty cell A10 is excluded from this count.

function 1-1

Explanation of the formulas: The preceding two formulas work as follows:

a. The COUNTIF function is instructed to count the non-blank cells within the range A2:A26. Since the ampersand operator (&) along with an empty string (“”) is supplied to the COUNTIF function, it treats the empty cell A10 as a unique value. So, the COUNTIF returns the following array of values:

{3;1;2;2;3;2;2;2;1;3;2;2;2;3;2;2;2;3;2;2;1;3;2;2;2}

b. Next, the values of the preceding array are divided by 1. This division returns the following array of values:

{0.333333333333333;1;0.5;0.5;0.333333333333333;0.5;0.5;0.5;1;0.333333333333333; 0.5;0.5;0.5;0.333333333333333;0.5;0.5;0.5;0.333333333333333;0.5;0.5;1;0.333333333333333;0.5;0.5;0.5}

c. At last, the single array is summed up by the SUM or the SUMPRODUCT functions. This returns 13 as the sum. From this sum, 1 is subtracted to exclude the empty cell from the count. So, the final output is 12.

Hence, Excel returns the same output irrespective of the formula used. Notice that in this example, the COUNTIF returned 1 for the single empty cell A10.

Likewise, had there been two empty cells in the range A2:A26, the COUNTIF would have returned 2 at two places in the array. For three empty cells, the COUNTIF would have returned 3 at three places in the array. So, the sum of all occurrences of empty cells is always equal to 1.

Therefore, the given two formulas would have returned the correct output even if there had been more than one empty cell in the supplied range.

Note: To view the array of values in pointers “a” or “b,” select the parts “COUNTIF(A2:A26,A2:A26&“”)” or “1/COUNTIF(A2:A26,A2:A26&“”)” of the formula. Next, press the key F9.

Frequently Asked Questions

1. Define unique values and state the formula for counting them in Excel.

Unique values are those that appear in a list of items only once. The formula for counting unique values in Excel is stated as follows:

“=SUM(IF(COUNTIF(range,range)=1,1,0))”

This formula works as follows:

a. The COUNTIF function is supplied with a single range twice. It counts the number of values that appear only once in the stated range. It returns an array of values.
b. The IF function considers the argument “COUNTIF(range,range)=1” as the logical test. If the COUNTIF returns 1, the IF function also returns 1 (value_if_true). However, if the COUNTIF returns a value other than 1, the IF function returns 0 (value_if_false). All ones returned by the IF function are unique values and all zeroes are duplicate values.
c. The SUM function sums the single array of ones and zeroes returned by the IF function.

The final output is the count of the unique values of the list of Excel.

Note 1: The given formula is an array formula. So, ensure that the CSE (Ctrl+Shift+Enter) keys are pressed after entering the formula in Excel. Exclude the beginning and ending double quotation marks while entering the formula in Excel.

Note 2: To extract the unique values, the duplicates need to be removed from the list.

2. Define distinct values and state the formula for counting them in Excel.

Distinct values are all the different values of a list of items. So, distinct values are the unique values plus the first occurrences of duplicate values.

To count the distinct values in Excel, either of the following formulas can be used (without the beginning and ending double quotation marks):
• “=SUM(1/COUNTIF(range,range))”
• “=SUMPRODUCT(1/COUNTIF(range,range))”

The only difference between the two formulas is that the former is completed with the CSE (Ctrl+Shift+Enter) keys, while the latter is completed with the “Enter” key.

Note: For more details on the working of the preceding formulas, refer to examples #1 and #2 of this article. For counting distinct values by excluding the empty cells, refer to example #3 of this article.

3. How to count the unique and distinct values by using the COUNTIFS function of Excel?

The formula for counting the unique rows of ranges A2:A12 and B2:B12 is stated as follows:

“=SUM(IF(COUNTIFS(A2:A12,A2:A12,B2:B12,B2:B12)=1,1,0))”

The formula for counting the distinct rows of ranges A2:A12 and B2:B12 is stated as follows:

“=SUM(1/COUNTIFS(A2:A12,A2:A12,B2:B12,B2:B12))”

Both the COUNTIFS formulas work similar to their COUNTIF counterparts. The benefit of using the COUNTIFS function is that it allows checking multiple columns for unique or distinct values.

Note: A row will be counted by the two formulas only if the cells in both columns A and B are unique (or distinct). Further, both the stated formulas are array formulas. So, do press the CSE (Ctrl+Shift+Enter) keys to complete these formulas.

Recommended Articles

This has been a guide to counting the unique and distinct values in Excel. Here, we explain top 2 easy methods along with step by step examples. You may also look at these useful functions of Excel–

  • Calculate SUMPRODUCT with Multiple CriteriaIn Excel, using SUMPRODUCT with several Criteria allows you to compare different arrays using multiple criteria.read more
  • COUNTIF with Multiple Criteria
  • ISNA Function in ExcelThe ISNA function is an error handling function in Excel. It helps to find out whether any cell has a “#N/A error” or not. This function returns the value “true” if “#N/A error” is identified or «false» if not identified.read more
  • OFFSET Excel ExampleThe OFFSET function in excel returns the value of a cell or a range (of adjacent cells) which is a particular number of rows and columns from the reference point. read more

Like this post? Please share to your friends:
  • How to do diagrams in microsoft word
  • How to draw with word
  • How to do diagrams in excel
  • How to draw with excel
  • How to draw picture in word