How to Count Unique Values with Criteria in Excel

📅 Jan 01, 2026 📝 Sarah Miller

Isolating unique data points under specific criteria in Excel is a notorious challenge that often leads to manual sorting errors. When analyzing complex datasets, such as tracking allocations across standard funding sources, traditional functions fall short. Fortunately, mastering modern dynamic arrays grants you the ability to extract precise, deduplicated metrics instantly. Please note the stipulation: this streamlined approach requires Excel 365 or 2021 to support dynamic arrays. For example, counting unique active projects within a specific department becomes effortless. Below, we break down the exact formula syntax and provide a step-by-step guide to implementation.

How to Count Unique Values with Criteria in Excel

Counting unique values is one of the most common tasks in Excel data analysis. Whether you are analyzing sales data to find the number of unique customers in a specific region, counting distinct active products within a category, or auditing employee shifts across different departments, you will frequently need to filter out duplicates before counting.

While Excel has a dedicated COUNTA function for counting cells and a COUNTIF function for counting with criteria, it historically lacked a direct, built-in function to count unique values based on conditions. Fortunately, depending on your version of Excel, there are several powerful formulas available to solve this problem. This comprehensive guide will walk you through the modern, easy-to-use methods available in Excel 365 and Excel 2021, as well as the classic legacy formulas required for older versions of Excel.


The Sample Dataset

To make these formulas easy to understand, we will use a consistent sample dataset throughout this guide. Imagine you have a sales tracking table in columns A and B:

Row A (Region) B (Customer)
2NorthAcme Corp
3SouthBeta LLC
4NorthAcme Corp
5NorthDelta Inc
6SouthAcme Corp
7NorthSigma Co
8SouthBeta LLC

Our goal in the following examples is to count the number of unique customers in the "North" region. Looking at our table, the customers in the North are Acme Corp (twice), Delta Inc, and Sigma Co. The unique count for the North region should be 3.


Method 1: The Modern Way (Excel 365 & Excel 2021)

If you are using Excel 365, Excel for the Web, or Excel 2021, you have access to Dynamic Array formulas. This makes counting unique values with criteria incredibly straightforward by nesting three functions: ROWS, UNIQUE, and FILTER.

The Formula

=ROWS(UNIQUE(FILTER(B2:B8, A2:A8 = "North")))

How It Works Step-by-Step

  1. FILTER(B2:B8, A2:A8 = "North"): This function looks at the Region column (A2:A8) and isolates the values in the Customer column (B2:B8) where the region is "North". It returns an in-memory array of: {"Acme Corp"; "Acme Corp"; "Delta Inc"; "Sigma Co"}.
  2. UNIQUE(...): This function takes the filtered array of customers and removes all duplicate entries. It refines our array down to: {"Acme Corp"; "Delta Inc"; "Sigma Co"}.
  3. ROWS(...): Finally, the ROWS function counts how many rows (items) are in our unique array. Since there are three names left, it returns 3.

Note: You can also use the COUNTA function instead of ROWS. However, ROWS is generally preferred because if the filter returns no matches, COUNTA might mistakenly return 1 instead of 0 due to how it evaluates empty errors.

Handling Empty Criteria and Errors

If there is a chance that your criteria will find no matches, the FILTER function will return a #CALC! error, causing the entire formula to break. To make your formula bulletproof, wrap it in an IFERROR function:

=IFERROR(ROWS(UNIQUE(FILTER(B2:B8, A2:A8 = "North"))), 0)

Method 2: The Classic Array Formula (Excel 2019 and Older)

If you are sharing your workbook with colleagues who use older versions of Excel (such as Excel 2016 or 2013), the UNIQUE and FILTER functions will not work. You must rely on a legacy array formula combining SUM, FREQUENCY, MATCH, and ROW.

The Formula

Important: If you are using Excel 2019 or older, you must press Ctrl + Shift + Enter after typing this formula instead of just hitting Enter. This will wrap the formula in curly braces { }.

=SUM(SIGN(FREQUENCY(IF(A2:A8="North", MATCH(B2:B8, B2:B8, 0)), ROW(B2:B8)-ROW(B2)+1)))

How It Works Step-by-Step

This formula is complex, but it can be broken down into logical phases:

  • The IF Filter: IF(A2:A8="North", MATCH(...)) checks if the region is "North". If true, it proceeds to the MATCH function; if false, it returns FALSE.
  • The MATCH Position Finder: MATCH(B2:B8, B2:B8, 0) finds the relative position of each customer in the list. For Acme Corp (which appears at row 2 and row 4), it will return position 1 both times because MATCH only ever finds the first occurrence.
  • The Bin Array: ROW(B2:B8)-ROW(B2)+1 generates a sequential array of numbers: {1; 2; 3; 4; 5; 6; 7}. These act as "bins" for our frequency count.
  • The FREQUENCY Distribution: The FREQUENCY function counts how many times each match position appears inside our bins. Since Acme Corp appears multiple times, its first match position gets a count of 2, while its duplicate occurrences get ignored.
  • The SIGN & SUM Cleanup: The SIGN function converts any positive count returned by FREQUENCY to a 1 (ensuring duplicates are only counted once). Finally, SUM adds up these 1s to give us our final count of 3.

Method 3: SUMPRODUCT & COUNTIFS (No Ctrl+Shift+Enter Required)

If you are on an older Excel version but want to avoid using the complex Ctrl + Shift + Enter array method, you can use a formula built around SUMPRODUCT and COUNTIFS. This method is slightly slower on massive datasets but is much easier to type and execute.

The Formula

=SUMPRODUCT((A2:A8="North") / COUNTIFS(A2:A8, A2:A8 & "", B2:B8, B2:B8 & ""))

How It Works

This approach divides the matching criteria by the total number of times each record occurs. If a customer in the North region appears twice, the expression evaluates to 1 / 2 twice. When SUMPRODUCT sums these two instances (0.5 + 0.5), they equal 1. This mathematically eliminates duplicates from the final tally.

Note: The & "" is appended to the criteria arrays to prevent division-by-zero errors (#DIV/0!) if your dataset contains any blank rows.


Summary Comparison of Methods

Method Excel Compatibility Complexity Performance on Large Data
ROWS + UNIQUE + FILTER Office 365 / Excel 2021+ Low (Highly Intuitive) Excellent (Fast)
SUM + FREQUENCY + MATCH All Versions (Legacy) High (Requires CSE) Good
SUMPRODUCT + COUNTIFS All Versions (Legacy) Medium Moderate (Can slow down large sheets)

Conclusion

For modern Excel users, the combination of ROWS, UNIQUE, and FILTER is hands-down the best approach to count unique values with criteria. It is clean, readable, incredibly fast, and handles edge cases beautifully when combined with IFERROR. However, if you are building dashboards or templates that must remain backward-compatible for users on older versions of Microsoft Office, mastering the legacy SUM/FREQUENCY or SUMPRODUCT methods will ensure your reports work seamlessly across all platforms.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.