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:
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:
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:
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:
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))
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:
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:
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:
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).
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:
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).
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
Muchas Gracias!!!!!!!!!!
Hi Alex,
I have below data, and want formula to get the result listed down.
Column A Column B
TA115 Matt
TA115 Rani
TA115 Rani
TA678. Swetha
TA678 Swetha
I need Unique entry of Application numbers which are in Row A & respective staff assigned to -
Example of the result -
Column C Column D
TA115 1
TA678. 1
Column C Column D Column E
TA115 1 Matt
TA678 1 Swetha
Hi! Sorry, it's not quite clear what you are trying to achieve. The example of results don't match your questions. Maybe this article will be helpful: Get a list of unique values in Excel.
Hi,
I am looking to count the number of unique species by their phyla in 3 different locations. I have a sheet with three columns: site, species, and phyla. The sites are A, B, and C. Species can be grouped into phyla. I am looking for a formula that can produce the number of unique species in each phyla category per site so that I can compare species richness across sites and make graphs that are color coded by phyla.
Trying the method described in the "Count unique values with multiple criteria" section produces an error. Seems like the error is with FILTER as that doesn't work by itself.
Here's an example of the sheet for visualization, but it is many thousands of rows in actuality. :)
site species phyla
A dalli arthropoda
A dalli arthropoda
A chondra rhodophyta
A caula rhodophyta
B dalli arthropoda
B glandula arthropoda
B egregia ochrophyta
B chondra rhodophyta
C dalli arthropoda
C egregia ochrophyta
C silvetia ochrophyta
C caula rhodophyta
Hi! I don't know what is not working for you, as you haven't written your formula. Use the recommendations from the article above and try this formula for an example:
=COUNTA(UNIQUE(FILTER(B2:B13,(C2:C13="arthropoda")*(A2:A13="A"))))
HI
I want to count unique value with condition, for example: i have 2 coulmns i want to filter 1401 and count unique value in coulumn requisit
Please help me.
TNX
Requisit year
656100 1401
656100 1401
692935 1402
338886 1398
334001 1398
307551 1398
307556 1398
313528 1398
325855 1398
304155 1398
325855 1398
648516 1401
648516 1401
648516 1401
648516 1401
Hi! Pay attention to the following paragraph of the article above – Count unique values with criteria.
It covers your case completely.
HI,
I have a Calculator worksheet that pulls the following from another worksheet in the workbook:
=COUNTIF('test page Cost Centers'!F:F,TRUE).
This is used to divide an invoice amt between certain providers by suite # (F:F)
Here are the column headings for the Calculator worksheet.
A B C D E F G J
Subtotl Tax Suite Specialty SubAcct #CostCtr ProviderCode Provider Name
The 'test page Cost Centers" worksheet has the following formula:
=C3=Calculator!$C$6
Here are the column headings for the Cost Center worksheet.
A B C D E F G
cost ctr Provider Suite Specialty (null) Match C Match D
How do I change the COUNTIF formula to count either the suite#(F:F) and/or the Specialty(D:D) when muliple specialty are in the same suite#?
I get a little confused with the unique values statement but think this is something needed to pull the numbers I need.
Thank you for your time.
Hi! To do counting on multiple conditions, use the COUNTIFS function. Here is the article that may be helpful to you: Excel COUNTIFS and COUNTIF with multiple AND / OR criteria. I hope it’ll be helpful.
Hi Sir, I have 3 columns of below:
Column A Column B Column C
20/7/2023 2023-07 Pizza Hut
21/7/2023 2023-07 KFC
22/8/2023 2023-08 Pizza Hut
23/8/2023 2023-08 KFC
24/8/2023 2023-08 Pizza Hut
25/8/2023 2023-08 KFC
I have used below formula to get the figure of count of KFC in 2023-08, but only get answer = 1
=IFERROR(ROWS(UNIQUE(FILTER($C:$C,($B:$B="2023-08")*($C:$C="KFC")))),0)
How to slot in the criteria with date (Column A) inside the formula to get answer =2 ?
Hi! Use column A to count unique values. Modify the formula:
=IFERROR(ROWS(UNIQUE(FILTER($A:$A,($B:$B="2023-08")*($C:$C="KFC")))),0)
Hi I would like to know how to count number of unique values that meets either of the criteria.
Taking the above example in “ Count unique values with criteria”, I want to count the total number of winners in basketball and volleyball.
May I know if there is a formula for such case? Thanks
Hi! To count the number of unique values by OR condition, use + (sum) instead of * (multiplication) in the formula. For example,
=IFERROR(ROWS(UNIQUE(FILTER(A2:A10, (B2:B10=F1) + (B2:B10=G1)))), 0)
Hi there,
I have 4 collumns
I have a table with values between rows 2 and 57, and between collumns C to F.
I want to count how many times in the whole table: Collumn C contains the text "On-Call" and the Collumn D OR Collumn E OR Collumn F text on the same row contains the text "Bank Holiday".
I can understand how I would do this if the intended logic was "and" where "or" is, but I cant figure out how to get it to work as I've written.
I've tried:
=COUNTIFS(C2:C57, "On-Call", OR(D2:D57="Bank Holiday",E2:E57="Bank Holiday",F2:F57="Bank Holiday"),"TRUE")
which didn't work.
Thanks!
Hi! The answer to your question can be found in this article: Count cells with multiple criteria (OR logic). For example,
=COUNTIFS(C2:C57, "On-Call", D2:D57,"Bank Holiday") + COUNTIFS(C2:C57, "On-Call", E2:E57, "Bank Holiday")
But wouldn't that count it twice? I'm after an "or" (not exclusive) not an "and" relationship between the contents of collumns D E and F. I want it to return a value of 1 if Collumn C contains "On-Call" and at least one (but potentially up to all 3) of collumns D E and F contain "Bank Holiday"
Hi! Try to use SUMPRODUCT function:
=SUMPRODUCT(--(C2:C20="On-call"),--(((E2:E20="Bank Holiday")+(F2:F20="Bank Holiday"))>0))
Hope this is what you need.
Hi,
Is there a way to use SPILL in a FILTER formula?
I've got a SPILL list of Unique locations.
=SORT(UNIQUE(TablePrint[Location]))
Secondly I want to show a dynamic list of Unique CaseID's for the locations.
=ROWS(UNIQUE(FILTER(TablePrint[Case ID];TablePrint[Location]=AO6)))
This works fine, but I have to fill the series manually to the same size as the first SPILL list.
I need to get that dynamically.
The Cell reference 'AO6' references to the first cell of the UNIQUE SPILL list of the first formula.
If I change this reference to 'AO6#' it give's a "#N/A".
I'm out of thoughts, so any help will be appreciated.
Ron
Hi! To extract the first value from an array of unique values, use the CHOOSEROWS function.
CHOOSEROWS(AO6,1)
I hope it’ll be helpful.
Hi, I have employee codes in column A, and their Gender in column B.
1234 Female
5678 Male
9101 Female
1213 Male
1234 Female
I want the count of females, excluding the duplicate values. For example, in the above table, the count of females should show 2 (Instead of 3) since 1234 is a duplicate value.
Hi! Pay attention to the following paragraph of the article above: Count unique values with criteria.
It covers your case completely.
Yes, it worked!
Please can you also help with the below
1234 Female United Kingdom
5678 Male Ireland
9101 Female United Kingdom
1213 Male Russia
1234 Female United Kingdom
Need the overall count of UK and Ireland employees excluding duplicates.
The formula I used: =IFERROR(ROWS(UNIQUE(FILTER(M643:M662,AF643:AF662="United Kingdom","Ireland"))),0)
It did not work. The above one is only pulling the count of United Kingdom. Please help
Hi! Using your data, the formula for calculating unique values by condition can be like this:
=IFERROR(ROWS(UNIQUE(FILTER(A1:C5,(C1:C5="United Kingdom")+(C1:C5="Ireland")))),0)
I recommend reading this guide: Excel FILTER function - dynamic filtering with formulas.
i need to distinct count with multiple criteria form raw data
Driver name City name 29-01-2023 30-01-2023 31-01-2023 01-02-2023
Anand K Bengaluru
Kumar K Bengaluru
Bheemana Gouda Bengaluru
Kakarla Sambamurthy Visakhapatnam
Hi! Your task is not completely clear to me. To calculate the number of values for several criteria, use this guide: How to use Excel COUNTIFS and COUNTIF with multiple criteria.
Hi, love this and have it working mostly, but i need some assistance with the way i have my data and formula.
For example if i have the following data, and i want to find how find how many unique models i have across Company 1 OR 2. The below should give a result of 3 unique models.
I would use =iferror(rows(unique(filter'A:A','B:B'=1))),0) to show me how many unique values for Company 1, but how do i get it to be either company 1 or 2.
col A Col B
Model Company
ABC 1
DEF 2
GHI 1
ABC 2
DEF 1
Hi!
If I understand correctly, just get the unique values in column A with the UNIQUE function. Сount these values using COUNTA function.
=COUNTA(UNIQUE(A:A))
Hello - I have a data tab where I have the following columns: Entity Name, Distribution Date, Distribution Amount
Is there a way to create a new column that would label each unique distribution in chronological orders?
Entity 1 and Entity 2 will both have a Distribution 1 label but might be on different dates
Thanks
Hi!
Unfortunately, I don't understand what you want to do. Give an example of the result.
Hi there,
I have been using this on a MacBook and I cannot get the command to work. I have a list of companies, which I cannot share due to confedeniality, but an overview is similar to this:
Company A - Acquisition 1 - USA
Company A - Acquisition 2 - USA
Company A - Acquisition 3 - France
Company B - Acquisition 1 - UK
Company B - Acquisition 2 - USA
Company B - Acquisition 3 - Japan
Company C - Acquisition 1 - USA
Company C - Acquisition 2 - China
Company C - Acquisition 3 - France
Company C - Acquisition 1 - Germany
Company C - Acquisition 2 - China
Company C - Acquisition 3 - China
So I want to count the number of countries that are acquired per Company but when I run the IFERROR(ROWS(UNIQUE(FILTER...) command every one comes out as zero. I ran it before and it worked fine but I cannot figure out if I am doing something wrong.
Thanks!
Dee
Hi!
I can't give advice on a formula that I don't see. Think about what has changed in your data.
Hi!
My apologies - I am relatively new to these forums and to data analyses within excel, so I am sorry for not giving the formula!
If the company names are in column A, and the countries in column C, then I am using =IFERROR(ROWS(UNIQUE(filter($C$2:$C$17220,$A$2:$A$17220=A2))),0)
I get the value of 0 for every row and cannot understand what I am doing wrong! Apologies for my ignorance if it is something obvious. I very very much appreciate any help you have to offer!
Thanks,
Dee
Hi!
Your formula works for me. There may be a problem with the version of Excel. Try the formula without IFERROR and you will see where the error is.
=ROWS(UNIQUE(FILTER($C$2:$C$17220,$A$2:$A$17220=A2)))
Hi Alex,
I have query, I have master data with different items.
I would like to have a unique count of multiple condition. That is unique count should come depending on the other columns condition. That is countifs(a2:a40,"UTCL", d2:d50,""&"" and so on..
Kindly help this without pivot table and array.
Regards
Iyer
Please clarify your specific problem or provide additional information to understand what you need.
Hello,
Client Engagement Team Lead Stage
Akanksha Hot
Akanksha Cold
Akanksha Cold
Akanksha Cold
Akanksha Hot
Akanksha Hot
Akanksha Hot
Akanksha Hot
Akanksha Warm
Akanksha Warm
Akanksha Warm
Akanksha Warm
Neha Hot
Neha Hot
Neha Hot
Neha Hot
Formula, as below requirement. Eg
Akanksha
Hot - 9
Cold - 3
Warm - 4
Hello!
You can find the examples and detailed instructions here: COUNTIF function in Excel - count if not blank, greater than, duplicate or unique.
Hi Ablebits Team, thank you for this post, this formula have saved me a lot of time and kudos for giving me new knowledge for my work.
I do have a question, in using the same data in your article, example on taking how many win for Basketball and under age 18 that use the below formula:
=IFERROR(ROWS(UNIQUE(FILTER(A2:A10, (B2:B10=F1) * (C2:C10<F2)))), 0)
how do I then extend this formula to see how many win for Basketball and Hockey under age 18 for example? I try part of the formula (B2:B10=AND("Basketball","Hockey")) in excel it doesn't work. Could you advise the best formula I can use for this issue?
Right now on my work I have similar issue on my data and I can't be able to find the best formula to count multiple criteria under the same column as above. Thank you in advance for your help!
Hi!
If you write the second criterion in cell G1, then add the second condition to the formula:
=IFERROR(ROWS(UNIQUE(FILTER(A2:A10, ((B2:B10=F1)+(B2:B10=G1)) * (C2:C10 < F2)))), 0)
See examples here: Filter based on AND as well OR criteria.
Hi,
I have a data of meetings which is datewise which is bifurcated week wise and month wise and then in house, video call and outdoor meetings. I want to pull the summary of this data like how many meetings are done per week unique, inhouse and outdoor.
I could extract the summary using countifs but cant find the unique fields. can you please help
Hi!
I don't see your data and I don't understand why you can't use the COUNTIFS function. Look for the example formulas here: Excel COUNTIFS and COUNTIF with multiple AND / OR criteria.
Also you can use SUMPRODUCT function to conditionally count cells with multiple criteria.
If this is not what you wanted, please describe the problem in more detail.
Date Week Month Action type Firm Name
10-Aug-22 2 August Indoor ABC
17-Aug-22 3 August Indoor DEF
26-Aug-22 4 August Indoor ABC
23-Aug-22 4 August Outdoor EFG
30-Aug-22 5 August Outdoor EFG
30-Aug-22 5 August Call XXX
1-Sep-22 1 September Outdoor YYY
1-Sep-22 1 September Outdoor KKK
15-Sep-22 3 September Call BBB
15-Sep-22 3 September Outdoor AAA
17-Sep-22 3 September Call BBB
17-Sep-22 3 September Indoor YYY
18-Sep-22 3 September Call YYY
20-Sep-22 4 September Outdoor XXX
20-Sep-22 4 September Outdoor ABC
This kindof data i have
for count i am using below mentioned formula but i want to count unique filed
{=COUNTIFS($D:$D,"September",$C:$C,"3",$E:$E,"Call")}
Please suggest what criteria to add
Hello!
I don't quite understand what unique records you want to count. I think these examples will help you: Count unique values with criteria. I hope it’ll be helpful.
I want to count unique firm name for the week for outdoor meeting or call or inhouse meeting. because in data we have met 2 or three firms multiple times but i want to count it as one. so unique count i need
Hi!
Then use the link to the article I gave you.
I am using MSO 2016 and lower version please suggest me formula for that.
Hi thanks for this.. can you please help me with some modification in the formula. Is there a way to exclude a certain name in the unique range. Like with the use if your example lets say i want to exclude david in the count.
Hello!
The answer to your question can be found in this article: How to get a list of unique values based on criteria.