How to Count Unique Numeric Values with Criteria in a Range in Excel

We have talked that how to count unique numeric values in a data set in Excel in the previous post. And this post will guide you how to count unique numeric values with criteria in the range in Excel 2013/2016 or Excel office 365. How do I count the unique numeric values with a criteria in a list of data with some duplicate values using a formula in Excel. And you can use a formula that uses the SUM function, the FREQUENCY function and the IF function to count unique values in a range based on a criteria in Excel.

COUNT Unique Numeric Values with Criteria


Assuming you have a list of data range A1:B6 in your worksheet and you wish to count the number of unique score numbers in grade “A” using a formula. And the below introduction will show you the ways to achieve the result. The generic formula is like this:

=SUM(–(FREQUENCY(IF(B2:B7=”A”,A2:A7),A2:A7)>0))

count unique numeric values criteria9

Note: if you are working in Excel 365 version, and you can use a dedicated function called UNIQUE to count unique values. It can be used to count unique values including numeric or text values.

Let’s See How This Formula Works:

=IF(B2:B7=”A”,A2:A7)

count unique numeric values criteria1

You can use the IF function to filter the value in column B if the grade value in Column B is “A”, then returns the value in Column A. and The result is in an array like this:

{90;85;FALSE;FALSE;90;FALSE}

count unique numeric values criteria2

You can notice that if the value is not grade “A”, and it will return the FALSE value. And this array is passed to the FREQUENCY function as the argument.

= FREQUENCY(IF(B2:B7=”A”,A2:A7),A2:A7)

count unique numeric values criteria3

The FREQUENCY function can be used to count each of numeric value in the above array list, and returns an array result, like this:

{2;1;0;0;0;0;0}

count unique numeric values criteria4

From the above array result, you can see that the FREQUENCY function returns zero for any numbers that appear more that once in the data array, which is why values are zero once a number has been counted.

=FREQUENCY(IF(B2:B7=”A”,A2:A7),A2:A7)>0

count unique numeric values criteria5

You need to test each values that is greater than zero. The array result is like this:

{TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE}

count unique numeric values criteria6

Echo “TRUE” value represents a unique numeric value in the range A2:A7, and you still need to add up the TRUE values with the SUM function.

=–(FREQUENCY(IF(B2:B7=”A”,A2:A7),A2:A7)>0)

count unique numeric values criteria7

The SUM function can be used to add up logic values in an array, and you need to coerce those values into 1 or 0 by the double negative operator

{1;1;0;0;0;0;0}

count unique numeric values criteria8

Finally, you can use the SUM function to adds these values up in the above result array and press “CTRL+Shift+Enter” keys to change this normal formula as an array formula, and return the total number is 2.

Related Functions


  • Excel SUM function
    The Excel SUM function will adds all numbers in a range of cells and returns the sum of these values. You can add individual values, cell references or ranges in excel.The syntax of the SUM function is as below:= SUM(number1,[number2],…)…
  • Excel FREQUENCY function
    TThe Excel FREQUENCY function calculates how often values occur within a range of values. And it will return a vertical array of numbers.The syntax of the FREQUENCY function is as below:= FREQUENCY (data_array, bins_array)…
  • Excel IF function
    The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])….

 

 

Related Posts

If Cell Begins with One of Three Supplied Characters
If Cell Begins with One of Three Supplied Characters

If you want to test values to see if they begin with some given specific characters like “x”, ”y”, or “z”, you can create a formula with COUNTIF and SUM functions to return results. EXAMPLE You can see “TRUE” or ...

Average per Week by Formula in Excel
Average per Week 1

We usually apply AVERAGE function or relevant functions to return average directly in Excel worksheet. But in some situations, only applying average relevant functions cannot figure out our problem. Sometimes we can create a formula with functions and mathematical operation ...

How to Sum if Contains an Asterisk
How to Sum if Contains an Asterisk 7

To add numbers together we need to apply SUM function. And if we want to add numbers based on some conditions, we can add criteria with the help of SUMIFS function, SUMIFS can filter data with multiple criteria effectively. If ...

How to Sum in Vertical Range
How to Sum in Vertical Range 8

If we want to add numbers based on some conditions in Excel worksheet, we can add criteria with the help of SUMIFS function, SUMIFS can filter data with multiple criteria effectively. In this article, we will introduce you the method ...

How to Sum in Horizontal Range
How to Sum in Horizontal Range9

To add numbers together we need to apply SUM function. But if we want to add numbers based on some conditions, we can add criteria with the help of SUMIFS function, SUMIFS can filter data with multiple criteria effectively. In ...

How to Sum with Criteria and Or Logic in Excel
How to Sum with Criteria and Or Logic in Excel 8

To add numbers together we need to apply SUM function. And if we want to add numbers based on some conditions, we can add criteria with the help of SUMIFS function, SUMIFS can filter data with multiple criteria effectively. If ...

How To Sum the Largest N Values in Excel

Sometimes we may want to sum the largest N numbers or top N numbers in a range. In this article, we will show you the method of “SUM the Largest N Numbers” by a simple formula which consist of SUMPRODUCT ...

How to Sum for Cell Contains Formula Only in Excel
How to Sum for Cell Contains Formula Only in Excel 9

Sometimes values are created by formulas in cells. If we want to sum values which are created by formulas from a range, but some values which are hardcoded also list in the same range, how can we filter out matched ...

How to Sum the Smallest N Values in Excel
How to Sum the Smallest N Values in Excel 15

Sometimes we may want to sum the first smallest N numbers in a range in Excel. In this article, we will show you the method of “SUM the Smallest N Numbers” by a simple formula which consist of SUMPRODUCT and ...

How to Subtotal Values for Groups and Only Keep One Subtotal for A Group in Column
How to Subtotal Values for Groups and Only Keep One Subtotal for A Group in Column14

Sometimes we may meet the case that subtotal values for different groups and only record a subtotal value for one group in a column, for other cells in this group, keep them blank. Today we will introduce you how can ...

Sidebar