Counting Unique Values in Excel with Criteria: A Comprehensive Guide
In Excel, counting unique values in a column is a common task that can be achieved using various methods. However, when you need to count unique values based on certain criteria, the process becomes a bit more complex. In this guide, we'll explore how to count unique values in a column with specific criteria using Excel's COUNTIF, COUNTIFS, and SUMPRODUCT functions.
Understanding the Problem
Let's say you have a dataset like this:
| Region | Sales | Product |
|---|---|---|
| East | 1000 | Product A |
| West | 1500 | Product B |
| East | 2000 | Product C |
| East | 1200 | Product A |
| Central | 1800 | Product B |
You want to count the unique products sold in each region. In this case, the East region has two unique products (Product A and Product C), the West region has one unique product (Product B), and the Central region has one unique product (Product B).

Using COUNTIF with Criteria
The COUNTIF function can count the number of cells that meet a specific criterion. To count unique values, we'll use an IF function to check if the product in the current row is the same as the product in the next row. If it's not, we'll count it as a unique value.
Here's the formula to count unique products in each region:
=COUNTIF($B$2:$B2, IF($A2=$A3, "", $B2))

This formula works as follows:
$B$2:$B2is the range of cells containing the products.IF($A2=$A3, "", $B2)checks if the region in the current row is the same as the region in the next row. If it is, it returns an empty string (""), which won't be counted by the COUNTIF function. If it's not, it returns the product in the current row.
Using COUNTIFS with Criteria
The COUNTIFS function can count the number of cells that meet multiple criteria. To count unique values, we'll use an IF function to check if the product in the current row is the same as the product in the next row. If it's not, we'll count it as a unique value. Then, we'll use COUNTIFS to count the number of unique products in each region.
Here's the formula to count unique products in each region:

=COUNTIFS($A$2:$A2, $A2, $B$2:$B2, IF($A2=$A3, "", $B2))
This formula works as follows:
$A$2:$A2is the range of cells containing the regions.$B$2:$B2is the range of cells containing the products.IF($A2=$A3, "", $B2)checks if the region in the current row is the same as the region in the next row. If it is, it returns an empty string (""), which won't be counted by the COUNTIFS function. If it's not, it returns the product in the current row.
Using SUMPRODUCT with Criteria
The SUMPRODUCT function can multiply ranges or arrays of numbers and then add up the results. To count unique values, we'll use an IF function to check if the product in the current row is the same as the product in the next row. If it's not, we'll count it as a unique value. Then, we'll use SUMPRODUCT to count the number of unique products in each region.
Here's the formula to count unique products in each region:
=SUMPRODUCT(IF($A$2:$A3=$A2, 1, 0) * IF($B$2:$B3<>"", 1, 0))
This formula works as follows:
IF($A$2:$A3=$A2, 1, 0)checks if the region in the current row is the same as the region in the next row. If it is, it returns 0. If it's not, it returns 1.IF($B$2:$B3<>"", 1, 0)checks if the product in the current row is not an empty string (""). If it's not, it returns 1. If it's an empty string (""), it returns 0.SUMPRODUCTmultiplies the two ranges of numbers and then adds up the results. The result is the number of unique products in each region.
Conclusion
In this guide, we've explored three methods to count unique values in a column with specific criteria using Excel's COUNTIF, COUNTIFS, and SUMPRODUCT functions. Each method has its own advantages and use cases, so choose the one that best fits your needs. With these formulas, you can efficiently analyze your data and gain valuable insights.






















