How to Count Unique Excel Values Based on a Condition
Question details
The user needs to calculate the number of distinct items in one column but only when a specific condition (such as 'Y' or 'N') is met in a corresponding column.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Filtering and summarizing large datasets where duplicate entries exist, and an accurate distinct count is needed based on specific categorical criteria.
- Observed behavior
- To extract a clean count of unique items meeting a specific Y/N criteria without manually deduplicating the data or double-counting repeated entries.
Ensure you are using a modern version of Excel or a compatible spreadsheet application that supports dynamic array functions, as older versions will return a #NAME? error.
Use Dynamic Array Formulas (FILTER, UNIQUE, COUNTA)
This is the most efficient and recommended method for modern spreadsheet software to count distinct items with conditions.
Dynamic array functions can process arrays of data seamlessly. By nesting FILTER inside UNIQUE, and wrapping it all in COUNTA, you can extract the exact number of distinct entries that match your criteria.
Click on the blank cell where you want the final unique count result to appear.
Type the formula =COUNTA(UNIQUE(FILTER(A2:A100,B2:B100="Y"))). Adjust the range A2:A100 to match the column containing your items, and B2:B100 to match your condition column.
Press Enter. The formula will first filter column A for rows where column B is 'Y', then isolate the unique values, and finally count them.

Use a PivotTable with Distinct Count (Older Versions)
A reliable alternative for older spreadsheet versions that do not support the FILTER and UNIQUE array functions.
Process Complex Data Easily with WPS Spreadsheet
WPS Office provides full support for advanced dynamic array functions like UNIQUE, FILTER, and COUNTA. You can directly apply these formulas to instantly count conditional unique values without dealing with legacy workarounds.
- 1. Open your dataset: Launch WPS Spreadsheet and open your existing Excel workbook (.xlsx).
- 2. Enter the formula: Select a blank cell and type =COUNTA(UNIQUE(FILTER(A:A, B:B="Y"))).
- 3. View your unique count: Press Enter to instantly get the accurate count of unique items matching your condition.

Frequently Asked Questions
Why does my unique count formula return a #NAME? error?
The #NAME? error occurs if you are using an older version of Excel or a spreadsheet program that does not support modern dynamic array functions like FILTER and UNIQUE. Upgrading to the latest WPS Office or a newer version of Microsoft Office will resolve this issue.
Can I count unique values based on multiple conditions at once?
Yes, you can add more conditions to the FILTER function by enclosing each condition in parentheses and multiplying them. For example: =COUNTA(UNIQUE(FILTER(A2:A100, (B2:B100="Y")*(C2:C100="Yes")))).
How do I prevent the formula from counting blank cells?
If there are empty cells in your filtered data, they might be counted as an empty string. You can exclude them by adding another condition to ignore blanks: =COUNTA(UNIQUE(FILTER(A2:A100, (B2:B100="Y")*(A2:A100<>"")))).




