logo
search
Function Problems

How to Count Unique Records with Multiple Criteria in Excel

Muhammad TalhaMuhammad Talha Oct 26, 2026 869 views

Question details

The user needs to count unique combinations of data entries while applying multiple specific criteria, such as size ranges and building names, without relying on helper columns.

How to Count Unique Records with Multiple Criteria in Excel
Product
Excel
Device & OS
not provided
Scenario
Filtering a dataset by multiple conditions (e.g., specific building name and size range) and then counting only the unique combinations of records that meet those exact conditions.
Observed behavior
Standard COUNTIF or COUNTIFS functions calculate total occurrences rather than unique records, making it difficult to tally distinct combinations based on complex multiple criteria in a single cell.
Before you start

Ensure you are using a modern spreadsheet version (such as Excel 365, Excel 2021, or the latest WPS Office) that supports dynamic array functions like UNIQUE and HSTACK.

Solution 1Recommended

Use UNIQUE, HSTACK, INDEX, and SUMPRODUCT Functions

Combine dynamic array functions with SUMPRODUCT to extract unique records and evaluate multiple mathematical conditions simultaneously in a single formula.

By using HSTACK, you can combine non-adjacent columns into a single array. The UNIQUE function then removes any duplicate rows from this new array. Finally, INDEX allows you to isolate specific columns from the unique array so SUMPRODUCT can apply your multiple criteria and count the matching rows.

1
Select the destination cell

Click on the cell where you want the final count of unique records to be displayed.

2
Combine columns with HSTACK and UNIQUE

Construct the base of your formula by typing UNIQUE(HSTACK(Range1, Range2, Range3)). For example: UNIQUE(HSTACK(SourceData!E2:E500, SourceData!G2:G500, SourceData!H2:H500)).

3
Isolate criteria columns using INDEX

Wrap the UNIQUE formula in an INDEX function to target specific columns for your criteria checks. For example, INDEX(UNIQUE(...), , 1) will return the first column of your unique array.

4
Apply criteria and wrap in SUMPRODUCT

Set up your logical tests by multiplying them together inside a SUMPRODUCT function. For instance: =SUMPRODUCT((INDEX(...) = "BuildingA") * (INDEX(...) >= 10) * (INDEX(...) <= 20)).

5
Execute the formula

Press Enter to calculate the result. The formula will evaluate the arrays and return the exact count of unique combinations meeting your defined parameters.

Use UNIQUE, HSTACK, INDEX, and SUMPRODUCT Functions
Formula Efficiency: This method completely eliminates the need for helper columns, keeping your spreadsheet clean and automatically updating when source data changes.
Powerful Spreadsheet Solution

Easily Handle Complex Formulas with WPS Office

WPS Spreadsheet provides robust support for advanced dynamic array formulas. You can seamlessly count unique records with multiple criteria using functions like UNIQUE, HSTACK, and SUMPRODUCT.

  1. 1. Open your spreadsheet: Launch WPS Office and open your workbook containing the source data.
  2. 2. Select the output cell: Click the exact cell where you want your complex count calculation to appear.
  3. 3. Input the array formula: Type out your formula utilizing SUMPRODUCT, UNIQUE, HSTACK, and INDEX to evaluate your criteria.
  4. 4. Calculate instantly: Press Enter. WPS Spreadsheet will immediately process the arrays and display your precise, filtered unique counts.
Fully compatible with Microsoft Excel formulas and file formats (.xlsx)Natively supports dynamic arrays like UNIQUE, FILTER, and HSTACKLightweight application with high performance for large datasetsFree built-in data analysis tools and intuitive interface
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't COUNTIFS work for counting unique values?

The COUNTIFS function is designed to count all instances that meet specified criteria, including duplicates. It does not have a built-in mechanism to filter out duplicate records before counting, which is why dynamic arrays like UNIQUE are necessary.

What does the HSTACK function do in this formula?

HSTACK horizontally combines separate, non-adjacent ranges or arrays into a single continuous array. This is critical for creating a unified table of data that the UNIQUE function can then process to find distinct combinations.

Can I use this formula in older versions of Excel?

No, functions like UNIQUE and HSTACK are dynamic array functions introduced in newer versions of spreadsheet software. You will need Microsoft 365, Excel 2021, or a fully updated version of WPS Office to execute them.

How does SUMPRODUCT evaluate multiple criteria?

In SUMPRODUCT, multiplying criteria arrays together (e.g., (Array1=Condition1)*(Array2=Condition2)) acts like an AND logic gate. True evaluations become 1s and False evaluations become 0s. The formula then sums the results, effectively counting how many rows met all conditions.