How to count unique values in Excel an easy way

The tutorial looks at how to leverage the new dynamic array functions to count unique values in Excel: formula to count unique entries in a column, with multiple criteria, ignoring blanks, and more.

A couple of years ago, we discussed various ways to count unique and distinct values in Excel. But like any other software program, Microsoft Excel continuously evolves, and new features appear with almost every release. Today, we will look at how counting unique values in Excel can be done with the recently introduced dynamic array functions. If you have not used any of these functions yet, you will be amazed to see how much simpler the formulas become in terms of building and convenience to use.

Note. All the formulas discussed in this tutorial rely on the UNIQUE function, which is only available in Excel 365 and Excel 2021. If you are using Excel 2019, Excel 2016 or earlier, please check out this article for solutions.

Count unique values in column

The easiest way to count unique values in a column is to use the UNIQUE function together with the COUNTA function:

COUNTA(UNIQUE(range))

The formula works with this simple logic: UNIQUE returns an array of unique entries, and COUNTA counts all the elements of the array.

As an example, let's count unique names in the range B2:B10:

=COUNTA(UNIQUE(B2:B10))

The formula tells us that there are 5 different names in the winners list:
Excel formula to count unique values in a column

Tip. In this example, we count unique text values, but you can use this formula for other data types too including numbers, dates, times, etc.

Count unique values that occur just once

In the previous example, we counted all the different (distinct) entries in a column. This time, we want to know the number of unique records that occur only once. To have it done, build your formula in this way:

To get a list of one-time occurrences, set the 3rd argument of UNIQUE to TRUE:

UNIQUE(B2:B10,,TRUE))

To count the unique one-time occurrences, nest UNIQUE in the ROW function:

ROWS(UNIQUE(B2:B10,,TRUE))

Please note that COUNTA won't work in this case because it counts all non-blank cells, including error values. So, if no results are found, UNIQUE would return an error, and COUNTA would count it as 1, which is wrong!

To handle possible errors, wrap the IFERROR function around your formula and instruct it to output 0 if any error occurs:

=IFERROR(ROWS(UNIQUE(B2:B10,,TRUE)), 0)

As the result, you get a count based on the database concept of unique:
Counting unique values that occur only once

Count unique rows in Excel

Now that you know how to count unique cells in a column, any idea on how to find the number of unique rows?

Here's the solution:

ROWS(UNIQUE(range))

The trick is to "feed" the entire range to UNIQUE so that it finds the unique combinations of values in multiple columns. After that, you simply enclose the formula in the ROWS function to calculate the number of rows.

For example, to count the unique rows in the range A2:C10, we use this formula:

=ROWS(UNIQUE(A2:C10))
Excel formula to count unique rows

Count unique entries ignoring blank cells

To count unique values in Excel ignoring blanks, employ the FILTER function to filter out empty cells, and then warp it in the already familiar COUNTA UNIQUE formula:

COUNTA(UNIQUE(FILTER(range, range<>"")))

With the source data in B2:B11, the formula takes this form:

=COUNTA(UNIQUE(FILTER(B2:B11, B2:B11<>"")))

The screenshot below shows the result:
Counting unique entries ignoring blank cells

Count unique values with criteria

To extract unique values based on certain criteria, you again use the UNIQUE and FILTER functions together as explained in this example. And then, you use the ROWS function to count unique entries and IFERROR to trap all kinds of errors and replace them with 0:

IFERROR(ROWS(UNIQUE(range, criteria_range=criteria))), 0)

For example, to find how many different winners there are in a specific sport, use this formula:

=IFERROR(ROWS(UNIQUE(FILTER(A2:A10,B2:B10=E1))), 0)

Where A2:A10 is a range to search for unique names (range), B2:B10 are the sports in which the winners compete (criteria_range), and E1 is the sport of interest (criteria).
Counting unique values with criteria

Count unique values with multiple criteria

The formula for counting unique values based on multiple criteria is pretty much similar to the above example, though the criteria are constructed a bit differently:

IFERROR(ROWS(UNIQUE(range, (criteria_range1=criteria1) * (criteria_range2=criteria2)))), 0)

Those who are curious to know the inner mechanics, can find the explanation of the formula's logic here: Find unique values based on multiple criteria.

In this example, we are going to find out how many different winners there are in a specific sport in F1 (criteria 1) and under the age in F2 (criteria 2). For this, we are using this formula:

=IFERROR(ROWS(UNIQUE(FILTER(A2:A10, (B2:B10=F1) * (C2:C10<F2)))), 0)

Where A2:B10 is the list of names (range), C2:C10 are sports (criteria_range 1) and D2:D10 are ages (criteria_range 2).
Counting unique values with multiple criteria

That's how to count unique values in Excel with the new dynamic array functions. I am sure you appreciate how much simpler all the solutions become. Anyway, thank you for reading and hope to see you on our blog next week!

Practice workbook for download

Count unique values formula examples (.xlsx file)

217 comments

  1. Hello,
    Can someone assist with how I would show the count of unique firms per manager?
    O2:O100 has Firm #
    Q2:Q100 has Manager Name
    I can find the count of the overall unique firms, but am having trouble inputting a formula just to show that specific manager's count.
    Thank you.

    • Hello!
      Please re-check the article above since it covers your task.
      Try to use the recommendations described in this paragraph: Count unique values with criteria.

  2. Hello.. Thank u for you sharing,
    There is another way to count unique with multiple criterias, if the criterias more than 20?. It takes to long syntax if i put one by one critera like you shared..

    Thank you so much..

  3. Hi Good day,

    Column A Column B Column C
    A AA XX
    A AA XX
    A AA XX
    A AB YY
    A AB XX
    B BB XX
    B BB XX
    B BC YY
    B BC XX
    B BC ZZ

    From the sample data above, I want to count how many distinct text in column C that group by column A)and column B. The result I wish to get is like this:

    Column A Column B Column C
    A AA XX 1
    A AA XX 1
    A AA XX 1
    A AB YY 2
    A AB XX 2
    B BB XX 1
    B BB XX 1
    B BC YY 3
    B BC XX 3
    B BC ZZ 3

    For group A, AA only XX in the group show 1 for each row, For group B,BC there are YY, XX and ZZ in it so show 3 for each of them.

    I've tried using this formula =
    SUM(--(FREQUENCY(IF($A$2:A2=A2,MATCH($C$2:C2,$C$2:$C2,0)),ROW($C$2:C2)-ROW(D2)+1)>0))
    but I didn't get what I want T.T

    Hope you understand my question. Thanks in advance for helping.

      • Thank you so much for reply.

        Sorry, forgot to tell. I'm using Microsoft Excel 2010 and it don't have function UNIQUE and FILTER. Is there any functions suitable for Microsoft Excel 2010 in this situation?

        Thanks again.

  4. Hello,

    I want to count what is the number of rooms based on the date entered and cell colour. If there is no date entered, I don't want it to be counted. The rooms is arranged in multiple rows and column.

    As example, the total number of blue cells is 458. In that 458, 110 cells have date meanwhile the rest is empty. So, how do I write formula for this as I am dealing with multiple colours as well.

  5. Hi, I'm trying to count unique values with multiple criteria but nothing seems to fit what I need.

    I have a sheet with data and a sheet with results within the same book.
    In a cell on the results sheet I am trying to count the number of unique items (job number) on the data sheet that match two sets of criteria, because the same criteria could have multiple lines under the same job number (for different months).

    Eg on the data sheet:
    Job# Month Customer Status
    123 Jan Joe's jugs Closed
    123 Feb Joe's jugs Closed
    124 Jan Joe's lamps Open
    125 Feb Jim's tables Closed
    126 Feb Joe's pots Closed

    I'm looking for the number of jobs on any account that belongs to Joe (so using a wildcard that Sumproduct can't handle) that are closed, but with unique job numbers (due to the spillover of job into other months). ie I'm trying to get a formula to give me a result of 2 [job 123 and 126], but can't find anything that works. Closest I've come is COUNTIFS, but I can't remove the duplicate job numbers so it will give me 3 [job 123 twice plus 126]. If I try to incorporate UNIQUE into that I get a SPILL error.

    • Hi!
      Please re-check the article above since it covers your task.
      Here is the formula for your task:

      =COUNT(UNIQUE(FILTER(A2:A6,(C2:C6="Joe’s")*(E2:E6="Closed"))))

  6. Hello -
    I'm trying to count the numbers of new projects in a certain type of work. Within a project might be multiple jobs, so i'm trying to count the unique project number by job type.

    I'm using the IFERROR(ROWS(UNIQUE(range, criteria_range=criteria))), 0) formula, but it is not pulling the expected results. It also changes the results if the table is filtered differently.

    Is there a way to send you my excel sheet for more info?
    =IFERROR(ROWS(UNIQUE(FILTER("Range of Project #'s","Range of job Types"="Job Type look for count of"))),0)

    Thank you!
    Chad

    • Hi!
      Please describe your task in more detail and send us a small sample workbook with the source data and expected result to support@ablebits.com. Please shorten your tables to 10-20 rows/columns and include the link to your blog comment.
      We'll look into your task and try to help.

  7. Hi, As per shared expample for Count unique values with criteria, I want to find the count of multiple sport for winners. Means if Andrew having intrest in 2 sports (like basketball- 2 and Hockey-1). I want answer number 2.

  8. in sheet1 at A:A i have data as medicine names, At sheet 2 from C:C i want to create autocomplete drop down list from the data , which should complete by just 2-3 letters, based on data at sheet1

    please help

    • Hello!
      Data Validation doesn't have an AutoComplete feature. You need to use Combo Box. To insert it, use the menu Developer > Insert > Combo Box (ActiveX Control).

  9. Hello,

    I am trying to determine the amount of "New Customers" we received in a given FY. This data has opportunities that are split between reps, giving me an extra "New Customer" since it has a different opportunity ID. I am trying to use countif in a column by "New Customer" while using Sumproduct on another column (account name) to not count any "New Customers" that have the same account name.

    • Hi!
      Unfortunately, without seeing your data it is difficult to give you any advice. Please provide me with an example of the source data and the expected result.

  10. I need help please. I want to count the active months of production from a specific date, including the zeros.... how do I do this if all the dates are different?

  11. Hello All,

    How do I find the total sum of repeated count in a column? E.g If I have A1, A2, A3, A3, A2, B2, B2. I want the sum of repeated count to be 6

  12. Hi, I need help please!
    Im trying to calculate how many unique delivery numbers I have that are
    A. under 30 days overdue
    B. inbetween 30 and 90 days overdue
    C. over 90 days over due.
    I've just tried =IFERROR(ROWS(UNIQUE(FILTER(E:E,C:C<31))),0) but it's counting ones that are over 90 days overdue too. is there something else I need to do to stop this?

  13. Hi there,

    Thank you for the article - really helpful. I'm looking for a way to list the unique values across an entire table or array. For example my table values look like:

    Apple Pear Orange
    Banana Lemon Apple
    Orange Banana Pineapple
    Berry Lemon Apple

    I want to generate the list of unique values only across the table:

    Apple
    Pear
    Orange
    Banana
    Lemon
    Pineapple
    Berry

    Any advice on the best way to extract this would be much appreciated!

  14. Hi. How can I count unique values under a column? I'm trying to see how much customer feedbacks there are. Let's say I want to know how many people said excellent or professional.

    Column F
    1. very professional and the service provided was excellent
    2. customer service was great
    3. professional
    4. my problem got resolved
    5. the woman I spoke with was excellent and professional

  15. Hi there

    I have a dataset with an ID number in column A and a response of yes or no to 2 questions in columns B & C. I am trying to get an accurate chart of the results, where i take a unique count of ID Number for each of the 3 outcomes to the 2 questions, YES & YES = Outcome 1, YES & NO = Outcome 2 and NO & YES is outcome 3.
    My problem is that ID number 1 below has returned a different response to Q1 in the first row than it did in row 2. So my results return a value for ID number 1 in outcome 1 and also a value for outcome 3. Where an ID number answers YES in Q1 it should always trump any additional response of NO. So the unique count for Outcome 3 should not include ID Number 1.
    I can do it manually and find the duplicates and remove the incorrect records, but this is a long process as the dataset is quite large. I need to automate this process in some way. Any help is most appreciated.

    ID Number Q1 Q2
    1 YES YES
    1 NO YES
    2 YES YES
    2 YES YES
    3 NO YES

    • Hello!
      If I got you right, the formula below will help you with your task:

      =IF(IF(COUNTIFS($A$2:$A$10,A2,$B$2:$B$10,"Yes")>0,"Yes","No") & IF(COUNTIFS($A$2:$A$10,A2,$C$2:$C$10,"Yes")>0,"Yes","No")="YesYes",1, IF(IF(COUNTIFS($A$2:$A$10,A2,$B$2:$B$10,"Yes")>0,"Yes","No") & IF(COUNTIFS($A$2:$A$10,A2,$C$2:$C$10,"Yes")>0,"Yes","No")="YesNo",2,3))

      I hope I answered your question. If something is still unclear, please feel free to ask.

  16. Hii Sir

    can u please clear it

    if use one row bt different words and finally i want particular word count so what formula i can use?

  17. I have a spreadsheet of census information which contains the columns "Surname", "Given Name", and "Occupation". Frequently the data in each of these columns is the same (people with the same occupation, people who have the same surname, or given name). I want to create a formula which will identify each unique value in the column, and then count the number of instances of that unique item. So for example, I want to count the number of people who have a specific occupation. Or the number of people who have a specific surname, etc. I am using this formula to find and sort the unique values in the column, and it is working fine:
    =SORT(UNIQUE(J2:J3135))
    What I'd like to add to it is " (nn)" at the end of the formula shown so that the output (for the occupation field) would look like this (where these are the unique values identified by the above formula in the J2:J3135 range):
    Apprentice (14)
    Artist (1)
    Blacksmith (4)
    Bookkeeper (2)
    Clergyman (3)
    ...etc.
    So far I am not having much luck adding the counting part of this.
    Many thanks in advance.

      • Hello Alexander,

        I am working on a spreadsheet that is live, and ever changing. The question asked above is the most similar to what I am attempting to do. The two column titles are "Job Number" and "Company". Here is an example:

        1 Company A
        2 Company A
        3 Company B
        4 Company C
        5 Company D
        6 Company D
        7 Company E

        The UNIQUE function I am using is working correctly. Each Rep generally has 50 assigned "Job Numbers". So, In Cell C1, I enter the unique formula, and it outputs correctly:

        Company A
        Company B
        Company C
        Company D
        Company E

        What I would now like to do, is link the output in Column C, with a Total in column D. With the end result being:

        Company A | 2
        Company B | 1
        Company C | 1
        Company D | 2
        Company E | 1

        From the article that you linked above, I see how you do this. However, as jobs complete, that column is removed. This is why I would like to tie Column C and Column D. If Company B is completed and removed, This is what the data then looks like:

        Company A | 2
        Company C | REF!
        Company D | 1
        Company E | 2
        | 1

        I really hope this makes sense haha!

  18. =COUNTIFS($J:$J,"name",$N:$N,"name") . one more column need to take and need distinct count from that . please help

  19. Dear Ablebits,

    I am trying to find the number of unique agents who sold in 1 week and didn't sell in the next week. Like in the table below, Agent 3 and 4 sold in week 1 and didn't sell in week 2.

    Date Week Agent Name Sales
    1/1/21 1 Agent 1 1
    1/1/21 1 Agent 2 1
    1/1/21 1 Agent 3 1
    2/1/21 1 Agent 1 1
    2/1/21 1 Agent 2 1
    2/1/21 1 Agent 3 1
    2/1/21 1 Agent 4 1
    3/1/21 1 Agent 1 1
    3/1/21 1 Agent 2 1
    3/1/21 1 Agent 3 1
    9/1/21 2 Agent 1 1
    9/1/21 2 Agent 2 1
    9/1/21 2 Agent 5 1
    10/1/21 2 Agent 1 1
    10/1/21 2 Agent 2 1
    10/1/21 2 Agent 5 1

    Using the unique count formula, I have tried using the formula below but I have been getting the calc error -
    FILTER(Daily_sales_data!O2:O10839,(Daily_sales_data!K2:K10839=E2-1)*(Daily_sales_data!K2:K10839=(E2-2)))
    where;
    Daily_sales_data!O2:O10839 - similar to Agent Name column above
    Daily_sales_data!K2:K10839 - similar to Week column above
    E2 = Week 3, so E2-1= Week 2 and E2-2= Week 1

    Can you help me know what I am doing wrong?

    • Hello!
      Your data is written in A2:D17 and the week number is written in E1. To calculate how many agents sold in week 1 and not sold in week 2, try the formula

      =SUM((COUNTIFS(C2:C17,UNIQUE(C2:C17),B2:B17,$E$1)>0) * (COUNTIFS(C2:C17,UNIQUE(C2:C17),B2:B17,$E$1+1)=0))

      Hope this is what you need.

  20. Hi Experts,

    Reaching out to seek for your kind support.
    I want to count the total unique numeric value in a columns that consist of different duplicates, each value should represent"1" count

    result for below column should be 6.

    Column B:

    1441
    1441
    1441
    80
    987
    987
    11
    11
    900
    540
    540

    many thanks!!

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)