Count unique values in a range in Excel
This tutorial explains how to count only the unique values among duplicates in a list in Excel with specified formulas.
How to count unique values in one column in Excel?
Supposing you have a products table as the below screenshot shown, to count only the unique values in the Product column, you can apply one of the below formulas.
Generic Formulas
=SUMPRODUCT(--(FREQUENCY(MATCH(range,range,0),ROW(range)-ROW(range.firstcell)+1)>0))
=SUMPRODUCT(1/COUNTIF(range,range))
Arguments
How to use these formulas?
1. Select a blank cell to output the result.
2. Enter one of the below formulas into the selected cell and press the Enter key.
=SUMPRODUCT(--(FREQUENCY(MATCH(D3:D16,D3:D16,0),ROW(D3:D16)-ROW(D3)+1)>0))
=SUMPRODUCT(1/COUNTIF(D3:D16,D3:D16))
Notes:
Explanation of formulas
=SUMPRODUCT(--(FREQUENCY(MATCH(D3:D16,D3:D16,0),ROW(D3:D16)-ROW(D3)+1)>0))
- MATCH(D3:D16,D3:D16,0): The MATCH function gets the position of each item in range D3:D16, if the values appear more than once in the data range, it will return the same position to get the array like this {1;2;3;2;1;1;3;2;1;1;1;2;3;2}.
- ROW(D3:D16)-ROW(D3)+1: Here the ROW function returns the row number of reference D3:D16 and D3, and you will get {3;4;5;6;7;8;9;10;11;12;13;14;15;16}-{3}+1.
- Each number in the array subtracts number 3 then adds 1 and finally returns {1;2;3;4;5;6;7;8;9;10;11;12;13;14}.
- FREQUENCY({1;2;3;2;1;1;3;2;1;1;1;2;3;2},{1;2;3;4;5;6;7;8;9;10;11;12;13;14}): The frequency function calculates how often each number occurs in the data array and returns an array of numbers like this {6;5;3;0;0;0;0;0;0;0;0;0;0;0}.
- SUMPRODUCT(--{6;5;3;0;0;0;0;0;0;0;0;0;0;0}>0):
=SUMPRODUCT(1/COUNTIF(D3:D16,D3:D16))
- COUNTIF(D3:D16,D3:D16): The COUNTIF function counts how often each value occurs in the range D3:D16, using all the same values as criteria. It returns an array like this {6;5;3;5;6;6;3;5;6;6;6;5;3;5}, which mean that Laptop appears 6 times, Projector appears 5 times and Display appears 3 times.
- 1/{6;5;3;5;6;6;3;5;6;6;6;5;3;5}: Each number in the array is divided by 1, and returns a new array as {0.166666666666667;0.2;0.333333333333333;0.2;0.166666666666667;0.166666666666667;0.2;
0.333333333333333;0.166666666666667;0.166666666666667;0.166666666666667;0.333333333333333;0.2;
0.333333333333333;}. - SUMPRODUCT({0.166666666666667;0.2;0.333333333333333;0.2;0.166666666666667;0.166666666666667;
0.2;0.333333333333333;0.166666666666667;0.166666666666667;0.166666666666667;0.333333333333333;0.2;
0.333333333333333;}): Then SUMPRODUCT function sums all numbers in the array and returns the final result as 3.
Related functions
Excel SUMPRODUCT function
The Excel SUMPRODUCT function can be used to multiply two or more columns or arrays together, and then get the sum of products.
Excel FREQUENCY function
The Excel FREQUENCY function calculates how often values occur within a range of values, and then returns a vertical array of numbers.
Excel MATCH function
The Excel MATCH function searches for a specific value in a range of cells, and returns the relative position of this value.
Excel ROW function
The Excel ROW function returns the row number of a reference.
Excel COUNTIF function
The Excel COUNTIF function is used to count the number of cells that meet a criterion.
Related formulas
Count Number Of Visible Rows In A Filtered List
This tutorial explains how to count number of visible rows in a filtered list in Excel with the SUBTOTAL function.
Count unique values with criteria
This step-by-step guide helps to count only unique values based on a specified criteria in another column
Count visible rows with criteria
This tutorial provides detailed steps to help you count visible rows with criteria.
Use COUNTIF on a non-contiguous range
This step-by-step guide demonstrates how to use the countif function on a non-contiguous range in Excel.
The Best Office Productivity Tools
Kutools for Excel - Helps You To Stand Out From Crowd
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...
Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)
- One second to switch between dozens of open documents!
- Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
- Increases your productivity by 50% when viewing and editing multiple documents.
- Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.