"Excel: Count Unique Values in Column with Criteria"

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:

RegionSalesProduct
East1000Product A
West1500Product B
East2000Product C
East1200Product A
Central1800Product 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).

How to Count Unique Values in Excel
How to Count Unique Values in Excel

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))

Finding and Counting Unique values with Example
Finding and Counting Unique values with Example

This formula works as follows:

  • $B$2:$B2 is 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:

Return Multiple Values in Excel Based on Single Criteria (3 Options)
Return Multiple Values in Excel Based on Single Criteria (3 Options)

=COUNTIFS($A$2:$A2, $A2, $B$2:$B2, IF($A2=$A3, "", $B2))

This formula works as follows:

  • $A$2:$A2 is the range of cells containing the regions.
  • $B$2:$B2 is 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.
  • SUMPRODUCT multiplies 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.

Make a distinct count of unique values in Excel – How To
Make a distinct count of unique values in Excel – How To
Sum a Column Based on Values in Another - Excel University
Sum a Column Based on Values in Another - Excel University
Multiple Column Data Validation Lists in Excel - How To - PakAccountants.com
Multiple Column Data Validation Lists in Excel - How To - PakAccountants.com
Distinct Count On Excel
Distinct Count On Excel
Vlookup with Multiple Columns in Excel 🎯Vlookup Multiple Values-Vlookup Multiple Criteria #excel
Vlookup with Multiple Columns in Excel 🎯Vlookup Multiple Values-Vlookup Multiple Criteria #excel
a poster showing the differences between counter and counter in an english language text is below it
a poster showing the differences between counter and counter in an english language text is below it
How to filter multiple columns based on single criteria in Excel?
How to filter multiple columns based on single criteria in Excel?
3 Ways to Remove Duplicates to Create a List of Unique Values in Excel - Excel Campus
3 Ways to Remove Duplicates to Create a List of Unique Values in Excel - Excel Campus
How to Use COUNT and COUNTA in Excel Step by Step
How to Use COUNT and COUNTA in Excel Step by Step
How to keep column header viewing when scrolling in Excel?
How to keep column header viewing when scrolling in Excel?
Highlight EVERY Other ROW in Excel (using Conditional Formatting)
Highlight EVERY Other ROW in Excel (using Conditional Formatting)
Excel VLOOKUP Mastering Multiple Columns
Excel VLOOKUP Mastering Multiple Columns
Excel COUNTIF function examples - not blank, greater than, duplicate or unique
Excel COUNTIF function examples - not blank, greater than, duplicate or unique
the top 26 excel formulas are displayed in this screenshoter's guide
the top 26 excel formulas are displayed in this screenshoter's guide
Excel Formula to Compare Two Columns and Return a Value (5 examples) - ExcelDemy
Excel Formula to Compare Two Columns and Return a Value (5 examples) - ExcelDemy
Use Average with Conditional Formatting in Excel
Use Average with Conditional Formatting in Excel
Excel SUMIFS and SUMIF with multiple criteria – formula examples
Excel SUMIFS and SUMIF with multiple criteria – formula examples
the basic excel formula is displayed in this screenshot
the basic excel formula is displayed in this screenshot
HOW TO COMPARE TWO COLUMNS IN EXCEL
HOW TO COMPARE TWO COLUMNS IN EXCEL
calculate gst in excel, how to calculate gst, gst calculator, gst calculator in excel
calculate gst in excel, how to calculate gst, gst calculator, gst calculator in excel
Easy Methods to Compare Columns in Excel
Easy Methods to Compare Columns in Excel
Create a Column Chart to Display Variance with Different Colors
Create a Column Chart to Display Variance with Different Colors
How to Use Column Chart in Excel
How to Use Column Chart in Excel