logo
search
Function Problems

How to Count Only Filtered Rows in Excel with COUNTIF and COUNTIFS

Partner EditorPartner Editor Oct 9, 2026 869 views

Question details

The user needs to count or calculate percentages for only visible rows in a filtered dataset based on specific conditions, bypassing the default behavior of COUNTIF and COUNTIFS.

How to Count Only Filtered Rows in Excel with COUNTIF and COUNTIFS
Product
Excel
Device & OS
not provided
Scenario
Counting specific values or calculating percentages of visible rows after applying a filter to a dataset.
Observed behavior
Standard COUNTIF and COUNTIFS formulas evaluate all rows within the specified range, including the rows that have been hidden by a filter, leading to inaccurate results for visible-only data.
Before you start

Ensure your data range is correctly filtered and identify the exact column you want to evaluate before typing in the complex nested formula.

Solution 1Recommended

Use SUMPRODUCT with SUBTOTAL and OFFSET

Since COUNTIF and COUNTIFS cannot ignore hidden rows, you must combine SUMPRODUCT, SUBTOTAL, and OFFSET to evaluate conditions exclusively on visible cells.

The SUBTOTAL function is unique because it can ignore rows hidden by a filter. By combining it with OFFSET, we can pass visible rows one by one to SUMPRODUCT, which then applies your specific criteria (like values >= 4).

1
Select the target cell

Click on the cell where you want the counted result or percentage to be displayed.

2
Enter the formula for a single condition

To count visible numeric values greater than or equal to 4 in the range C9:C210, type: =SUMPRODUCT(SUBTOTAL(2,OFFSET(C9:C210,ROW(C9:C210)-MIN(ROW(C9:C210)),,1))*(C9:C210>=4))

3
Calculate a percentage of visible rows

If you want the percentage instead of a raw count, divide the formula by the total number of visible numeric cells: =SUMPRODUCT(SUBTOTAL(2,OFFSET(C9:C210,ROW(C9:C210)-MIN(ROW(C9:C210)),,1))*(C9:C210>=4))/SUBTOTAL(2,C9:C210)

4
Enter the formula for multiple conditions

To count values in a range, such as greater than or equal to 3 but less than 4, multiply the conditions together: =SUMPRODUCT(SUBTOTAL(2,OFFSET(C9:C210,ROW(C9:C210)-MIN(ROW(C9:C210)),,1))*(C9:C210>=3)*(C9:C210<4))

5
Execute the calculation

Press the Enter key. The cell will now display the accurate count or percentage based exclusively on your currently filtered data.

Use SUMPRODUCT with SUBTOTAL and OFFSET
Understanding the function parameters: In the SUBTOTAL function, the number '2' represents the COUNT function, which counts numeric values. If your column contains text instead of numbers, change the '2' to '3' (which represents COUNTA) to properly count visible text cells.
Advanced Spreadsheet Formulas

Count Filtered Rows Easily in WPS Spreadsheet

WPS Spreadsheet fully supports advanced array functions like SUMPRODUCT, SUBTOTAL, and OFFSET, allowing you to seamlessly calculate visible rows with complex conditions just like in Excel.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the document containing your data.
  2. 2. Apply filters: Navigate to the Data tab and click the Filter button to hide the rows you do not want to evaluate.
  3. 3. Insert the nested formula: Select an empty cell and paste the combined =SUMPRODUCT(SUBTOTAL(...)) formula adjusted for your specific data range.
  4. 4. Get precise results: Press Enter to instantly calculate the count or percentage based only on the rows visible on your screen.
100% compatible with Microsoft Excel formulas and array functionsFree and lightweight spreadsheet softwareSeamlessly handles advanced data filtering and complex logic
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't COUNTIF or COUNTIFS ignore hidden rows?

By design, COUNTIF and COUNTIFS evaluate the entire specified range, regardless of whether rows are hidden manually or via a filter. To conditionally evaluate only visible rows, you must use visibility-aware functions like SUBTOTAL or AGGREGATE combined with SUMPRODUCT.

Can I use this formula to count text values instead of numbers?

Yes. The example formula uses SUBTOTAL(2, ...), where '2' stands for COUNT (numeric values). To count text, change the '2' to '3', which stands for COUNTA (counts non-empty cells). The formula becomes =SUMPRODUCT(SUBTOTAL(3,OFFSET(...))*(C9:C210="YourText")).

Will this formula update automatically if I change the filters?

Yes. The SUBTOTAL function is dynamic. Whenever you change, apply, or clear filters in your dataset, the formula will instantly recalculate to reflect the newly visible rows.