Function Problems

How to Count Unique Values After Filtering Rows in Excel

Phi Hung VoPhi Hung Vo Oct 26, 2026 868 views

Question details

The user needs an Excel formula to count unique text values while excluding zeros, ensuring the count dynamically updates when rows are hidden using AutoFilter.

How to Count Unique Values After Filtering Rows in Excel
Product
Excel
Device & OS
not provided
Scenario
Counting unique records in a dataset where some rows are temporarily hidden or filtered out by the user.
Observed behavior
Standard formulas like SUMPRODUCT or COUNTIF calculate the unique values for the entire range, returning incorrect results because they do not ignore rows hidden by AutoFilter.
Before you start

Ensure your dataset is organized in a clear tabular format without merged cells, and identify the exact column you want to evaluate for unique values.

Solution 1Recommended

Use a Visibility-Aware Array Formula (Recommended)

This solution uses a combination of SUBTOTAL, OFFSET, FREQUENCY, and MATCH to actively detect and exclude hidden rows while counting unique values.

To make a formula ignore hidden rows, you must use the SUBTOTAL function. By nesting it with OFFSET, you can evaluate the visibility of each row individually.

When combined with FREQUENCY and MATCH, the formula can successfully identify unique values only within the currently visible data.

1
Select the target cell

Click on the empty cell where you want the dynamic unique count to appear.

2
Enter the array formula

Type the following formula, adjusting the ranges (e.g., E9:E34 for the data range, H9:H34 if testing for zeros): =SUM(IF(FREQUENCY(IF(SUBTOTAL(103,OFFSET(E9,ROW(E9:E34)-ROW(E9),,1)),IF(E9:E34<>0,MATCH(E9:E34,E9:E34,0))),ROW(E9:E34)-ROW(E9)+1),1))

3
Confirm as an array formula

If you are using a version prior to Excel 365, do not just press Enter. Instead, press Ctrl + Shift + Enter to confirm the formula. Curly braces {} will appear around the formula in the formula bar.

4
Apply absolute references for copying

If you need to drag this formula across multiple columns, add dollar signs to lock the references (e.g., $E$9:$E$34) before copying.

Understanding SUBTOTAL Code 103: The number 103 in the SUBTOTAL function corresponds to the COUNTA function, which specifically tells Excel to ignore rows that have been manually hidden or filtered out.
Advanced Data Analysis

Count Unique Filtered Data Effortlessly with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array calculations, allowing you to use complex nested formulas like SUBTOTAL, FREQUENCY, and OFFSET to count unique visible values. It is highly compatible with Microsoft Excel formulas.

  1. 1. Open your dataset in WPS Spreadsheet: Launch WPS Office and open the workbook containing the data you need to analyze.
  2. 2. Apply AutoFilter: Highlight your headers, navigate to the 'Data' tab, and click 'Filter' to hide the rows you do not need.
  3. 3. Select a cell for the result: Click on an empty cell to act as your counter display.
  4. 4. Enter the array formula: Paste your nested visibility-aware formula (using SUBTOTAL and MATCH) into the formula bar.
  5. 5. Calculate the unique count: Press Ctrl + Shift + Enter to lock in the array formula and get the accurate count of unique filtered items.
100% compatible with Microsoft Excel array formulas and functions.Fast processing of large datasets with complex criteria.Built-in advanced filtering and data analysis tools at no cost.User-friendly interface that feels instantly familiar.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my standard COUNTIF formula include hidden rows?

Standard functions like COUNTIF and SUMPRODUCT evaluate all cells within a specified range, regardless of their visual state. To exclude hidden rows, you must use functions explicitly designed to evaluate visibility, such as SUBTOTAL or AGGREGATE.

How can I count unique values in Excel 365 without complex array formulas?

In Excel 365, you can avoid complex older array formulas by combining the new UNIQUE and FILTER functions. However, to exclude manually filtered rows, you still need to incorporate a helper column or the SUBTOTAL function within the FILTER criteria.

What is the difference between SUBTOTAL 3 and SUBTOTAL 103?

Both codes perform a COUNTA operation. However, code 3 only ignores rows hidden by a filter, while code 103 ignores rows hidden by a filter AND rows that were manually hidden by right-clicking and selecting 'Hide'. Using 103 is generally safer for excluding all non-visible data.