Count unique distinct values in a column in excel
Question:
I have a list of values (A1:A6), how do I count unique distinct values?
Answer:
Unique distinct values are all values but duplicates are merged into one distinct value. See picture below.

Unique distinct values are calculated in cell C1. Unique values are calculated in cell C3.
Array Formula in C1:
How to create an array formula
- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar.
- Press and hold Ctrl + Shift.
- Press Enter once.
- Release all keys.
There are three distinct unique values. (AA, BB and CC)
EDIT: Alternative array formula in C1:
And another alternative array formula in C1:
Alternative array formula (No array formula!!)
If cell range also contains possible blank cells:
Alternative array formula (possible blank cells)
How the formula works
=SUM(1/COUNTIF(List1, List1))
COUNTIF(List1, List1) counts the number of cells within a range that meet the given condition.
COUNTIF(List1, List1) becomes COUNTIF((AA, BB, AA, CC, BB, AA), (AA, BB, AA, CC, BB, AA)) and returns the array:
(3, 2, 3, 1, 2, 3)
AA - 3 (AA exists 3 times in range List1)
BB - 2 (BB exists twice in range List1)
AA - 3
CC - 1
BB - 2
AA - 3
=SUM(1/(3, 2, 3, 1, 2, 3))
becomes
SUM(1/3, 1/2, 1/3, 1/1, 1/2, 1/3)
1/3 + 1/2 + 1/3 + 1/1 + 1/2 + 1/3 = 3
Download excel example file
count-unique-distinct-values-in-a-column.xls
(Excel 97-2003 Workbook *.xls)
Recommended blog posts
If you are working with a large data set, array formulas demonstarated in this post may be too slow. This post describes how to count unique distinct values in a a large data set:
Count unique distinct values in a large dataset with a date criterion
Count unique values in a column
Unique values are values existing only once in a list or range. See picture below.


Array formula in C3:
There are only one unique value (CC) in the list, all other values have duplicates.
Explaining formula in cell C3
=SUM(IF(COUNTIF(List1,List1)=1,1,0))
COUNTIF(List1, List1) counts the number of cells within a range that meet the given condition.
COUNTIF(List1, List1)
becomes
COUNTIF((AA, BB, AA, CC, BB, AA), (AA, BB, AA, CC, BB, AA)) and returns the array:
(3, 2, 3, 1, 2, 3)
IF(3, 2, 3, 1, 2, 3) = 1,1,0)
becomes
(0,0,0,1,0,0)
SUM(0,0,0,1,0,0) equals 1
0 + 0 + 0 + 1 + 0 + 0 = 1
Named ranges
List1 (A1:A6)
What is named ranges?
How to customize the formula to your excel workbook
Change the named ranges.
Download excel example file
count-unique-distinct-values-in-a-column.xls
(Excel 97-2003 Workbook *.xls)
Recommended blog posts:
Count unique distinct records in excel 2007
Functions used in this blog post:
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition
IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE
ROW(reference) returns the rownumber of a reference
MATCH(lookup_value;lookup_array; [match_type])
Returns the relative position of an item in an array that matches a specified value
SUM(number1,[number2],)
Adds all the numbers in a range of cells
MIN(number1,[number2])
Returns the smallest number in a set of values. Ignores logical values and text
This blog article is one out of twelve articles on the same subject "count unique and unique distinct".
- Count unique values in a column in excel
- Count unique distinct values in two columns in excel
- Count unique distinct values in three columns combined in excel
- Count unique values and unique distinct values in three ranges combined in excel
- Count unique and unique distinct values in a multicolumn range in excel
- Count unique values and unique distinct values in two ranges combined
- How to count unique combined column values
- How to count unique distinct records in a date range
- Count unique distinct records in a date range and a numeric range in excel
- Count unique distinct values in two columns with date criteria in excel
- Count unique distinct months in excel
- Count duplicate distinct values in a column in excel






May 5th, 2010 at 3:04 am
It is the same theme in my previous comment. The ability to count unique entries with blank cells in the range.
December 31st, 2010 at 5:42 pm
[...] Count unique distinct values in a column in excel [...]
March 5th, 2011 at 9:43 am
Can it be case sensitive?
AA
BB
aa
CC
BB
Aa
March 7th, 2011 at 9:57 am
Andy,
Great question, I don´t have an answer yet.
October 13th, 2011 at 11:22 am
Breathtakingly simple and elegant solution:
=SUMPRODUCT(1/COUNTIF(List1, List1)) + ENTER
Many thanks
February 22nd, 2012 at 5:58 pm
Thanks, this is great stuff. Much better than the stuff over at http://office.microsoft.com/en-us/excel-help/count-the-unique-entries-in-a-column-of-data-HA001044862.aspx
February 22nd, 2012 at 10:32 pm
lambertwm,
thanks!