If you need to count unique numeric values in a range, you can use a formula that uses the FREQUENCY function together with the SUM function.

For example, assume you have a list of employee numbers together with hours worked on "Project X", and you want know how many employees worked on thatĀ project. Looking at the data, you can see that the same employee numbers appear more than once, so what you want is a count of the unique employee numbers that appear in the list.

The employee numbers appear in the range B3:B12. To get a count of unique numbers, you can use the following formula:

### How this formula works

The FREQUENCY function returns an array of values that correspond to "bins". In this case, we are supplying the same set of numbers for both the data array and bins array.

The result is that FREQUENCY returns an array of values that represent a count for each numeric values in the data array. This works because FREQUENCY has a special feature that automatically returns zero for any numbers that appear more than once in the data array, so the return array looks like this:

Next, each of these values is tested to be greater than zero. The result looks like this:

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

Now each TRUE in the list represents a unique number in the list, and we just need to add up the TRUE values with SUM.

However, SUM won't add up logical values in an array, so we need to first coerce the values into 1 or zero. This is done with the double-hyphen (double-unary). The result an array of only 1's or 0's.

Finally, SUM adds these values up and returns the total, which in this case is 4.

*Note: you could also use SUMPRODUCT to sum the items in the array.*

### Using COUNTIF instead of FREQUENCY to count unique values

Another way to count unique numeric values is to use COUNTIF instead of FREQUENCY. This is a much simpler formula, but beware that using COUNTIF on larger data sets to count unique values can cause performance issues. The FREQUENCY-based formula, while more complicated, calculates much faster.