logo
search
Function Problems

How to Count Distinct Visible Values Based on Priority in Excel

Phi Hung VoPhi Hung Vo Oct 9, 2026 870 views

Question details

The user needs to extract a distinct count of visible items from a filtered data export while factoring in a specific priority condition.

How to Count Distinct Visible Values Based on Priority in Excel
Product
Excel
Device & OS
not provided
Scenario
Analyzing a daily SAP export where rows are filtered and contain duplicate transaction descriptions, requiring a formula to count only unique, visible cells that meet a priority criteria.
Observed behavior
Standard counting functions include hidden rows and duplicates. A dynamic formula is needed to isolate and count only unique, visible values meeting the specified conditions.
Before you start

Ensure your dataset is properly formatted as a table or range without merged cells, and identify the exact column references for your values and priority conditions before applying the formula.

Solution 1Recommended

Use Dynamic Array Functions to Count Unique Visible Rows

Combine modern array functions like UNIQUE, FILTER, BYROW, and SUBTOTAL to accurately count distinct visible items meeting your criteria.

This method leverages Excel's dynamic array functions to evaluate visibility and distinctness in memory, without requiring extra helper columns.

1
Identify your data ranges

Determine the range containing the values you want to count (e.g., L3:L21) and the range containing your priority conditions. Ensure both ranges are exactly the same size.

2
Create the visibility array

Use the BYROW and SUBTOTAL functions to create an array that identifies visible rows: BYROW(L3:L21, LAMBDA(a, SUBTOTAL(3,a))). This returns 1 for visible rows and 0 for hidden rows.

3
Apply the FILTER and UNIQUE functions

Nest this array inside a FILTER function along with your priority condition (e.g., PriorityRange="High"), then wrap it in UNIQUE to extract only distinct values. The multiplication operator (*) is used to combine conditions.

4
Count the final array

Enclose the entire formula in a COUNTA function: =COUNTA(UNIQUE(FILTER(L3:L21, (BYROW(L3:L21,LAMBDA(a,SUBTOTAL(3,a)))) * (PriorityRange="High")))). Press Enter to get your distinct visible count.

Use Dynamic Array Functions to Count Unique Visible Rows
Version Compatibility: This solution relies on dynamic array functions (FILTER, BYROW, LAMBDA), which are available in modern versions of Excel and WPS Spreadsheet. Older versions will return a #NAME? error.
Advanced Data Analysis

Count Complex Data Sets Easily with WPS Spreadsheet

WPS Spreadsheet fully supports modern dynamic array functions like UNIQUE, FILTER, and BYROW, making it incredibly easy to handle complex data exports from SAP without relying on clunky workarounds.

  1. 1. Open your Data: Launch WPS Spreadsheet and open your daily SAP export or project file.
  2. 2. Apply the Formula: Select a blank cell and input the combination formula: =COUNTA(UNIQUE(FILTER(L3:L21, BYROW(L3:L21,LAMBDA(a,SUBTOTAL(3,a)))))) adjusted for your specific ranges.
  3. 3. Filter and Update: Apply your data filters directly from the Data tab; WPS Spreadsheet will instantly recalculate and display the accurate distinct visible count.
Fully compatible with Microsoft Excel formulas and data formats (.xlsx).Supports advanced dynamic array functions for seamless data analysis.Lightweight and handles large daily SAP exports with high performance.Free to use with a familiar, user-friendly interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my regular COUNTIF or COUNTIFS include hidden rows?

Standard COUNT functions in spreadsheet software evaluate all cells in the specified range regardless of their visibility. To exclude hidden rows, you must integrate the SUBTOTAL or AGGREGATE function into your logic.

Can I use SUMPRODUCT instead of dynamic arrays for this task?

Yes, in older versions without dynamic arrays, you can combine SUMPRODUCT, SUBTOTAL, OFFSET, and COUNTIF to count distinct visible rows. However, this formula is significantly more complex and can slow down performance on large datasets.

What does the '3' mean in the SUBTOTAL function?

The '3' in the SUBTOTAL function corresponds to the COUNTA function, which counts non-empty cells. If you want to ignore rows hidden manually (not just hidden by filters), use '103' instead.

Why do I get a #NAME? error when using BYROW?

The #NAME? error typically means your version of Excel or WPS Office is older and does not natively support the BYROW or LAMBDA functions. Ensure your software is updated to the latest version that supports dynamic array formulas.