SUBTOTAL Function

SUBTOTAL Function

SUBTOTAL Function

Performs a calculation such as SUM or AVERAGE while respecting filtered rows.

ExcelClash Team
PUBLISHED

Summary

The Excel SUBTOTAL function performs a calculation such as SUM, AVERAGE, COUNT, MAX, or MIN on a list or database. Its distinguishing feature is that it can ignore rows hidden by filtering, which makes it useful for totals that need to respond to the current visible view of the data.

SUBTOTAL also avoids double-counting other SUBTOTAL formulas inside the referenced range. That makes it suitable for reports with several subtotal lines and a larger total that should still be based on the underlying data rather than on intermediate subtotal rows.

Purpose

Aggregate visible data

Use SUBTOTAL when the calculation should respond to filtering or hidden-row behavior.

Return Value

A single aggregate result

The returned value depends on the function code you choose, such as SUM, AVERAGE, COUNT, MAX, or MIN.

Syntax

=SUBTOTAL(function_num, ref1, [ref2], ...)

The first argument selects the type of calculation. Microsoft documents two code groups: 1-11 and 101-111. Both exclude filtered-out rows, but the 100-series also excludes rows hidden manually.

Arguments

  • function_num - [required] A code that selects the calculation to perform.
  • ref1 - [required] The first range to evaluate.
  • ref2, ... - [optional] Additional ranges, up to 254 references total.

Common Function Codes

Code Function Manual Hidden Rows Ignored?
1 / 101 AVERAGE No / Yes
2 / 102 COUNT No / Yes
3 / 103 COUNTA No / Yes
9 / 109 SUM No / Yes

Using SUBTOTAL

A common use of SUBTOTAL is a filter-aware total row. If a report is filtered by region, product, or status, a normal SUM continues to calculate all rows in the range, including the ones no longer visible. SUBTOTAL recalculates against the visible set instead, which is why it is a standard choice in filtered reports.

The function number is not a minor detail. It determines both the type of aggregation and, depending on whether you use the 1-11 group or the 101-111 group, whether manually hidden rows should still be counted. That distinction matters in worksheets where some rows are hidden for presentation rather than by filter logic.

SUBTOTAL also has an architectural advantage in layered reports: nested SUBTOTAL results are ignored. If a range already contains subtotal rows, a higher-level SUBTOTAL over that range still reads the underlying data correctly. That behavior helps prevent accidental double-counting in structured worksheet summaries.

Example 1 - Sum the Visible Rows

This is the most common use of SUBTOTAL.

=SUBTOTAL(9,B1:B5)

Code 9 means SUM. If all rows are visible, the result matches a normal SUM. Once a filter is applied, the result changes to reflect only the visible rows. That is the main reason to choose SUBTOTAL over SUM in filter-driven reports.

Check Answer
Challenge #1
Target: Sheet1!F1
Sum Visible Rows

In cell F1, use SUBTOTAL with code 9 to sum B1:B5.

Example 2 - Count Visible Non-Empty Cells

SUBTOTAL is not limited to sums.

=SUBTOTAL(3,B1:B5)

Code 3 means COUNTA, so the result is the number of visible non-empty cells in the range. This is useful for report headers, filtered record counts, and quick audit summaries.

Check Answer
Challenge #2
Target: Sheet1!F2
Count Non-Empty Visible Cells

In cell F2, use SUBTOTAL with code 3 to count non-empty visible cells in B1:B5.

Example 3 - Average the Current View

The visible rows can be treated as a working subset of the data.

=SUBTOTAL(1,B1:B5)

Code 1 means AVERAGE. If a filter narrows the list to a subset of rows, the average reflects that subset rather than the full range. That makes SUBTOTAL useful for interactive reports where the filter state changes frequently.

Check Answer
Challenge #3
Target: Sheet1!F3
Average of Visible Rows

In cell F3, use SUBTOTAL with code 1 to average B1:B5.

Example 4 - Ignore Manually Hidden Rows Too

The 100-series codes change hidden-row behavior.

=SUBTOTAL(109,B1:B5)

Code 109 also performs SUM, but unlike code 9 it excludes rows hidden manually as well as rows hidden by filtering. This version is more suitable when hidden rows should be fully excluded from the reported result.

Check Answer
Challenge #4
Target: Sheet1!F4
Ignore Manually Hidden Rows

In cell F4, use SUBTOTAL with code 109 to sum B1:B5 while also ignoring manually hidden rows.

SUBTOTAL is used automatically by the Total Row feature in Excel Tables. That is a good reminder that the function is not just a formula trick; it is part of how Excel itself handles visible-row summaries.

  • Codes 1-11 include manually hidden rows.
  • Codes 101-111 exclude manually hidden rows.
  • Filtered-out rows are excluded in both code groups.

Conclusion Recap

  • Summary: SUBTOTAL aggregates data while respecting filtered rows.
  • Main advantage: It adapts to the visible state of the dataset.
  • Important detail: The function code controls both the aggregation type and hidden-row behavior.
  • Reporting benefit: Nested SUBTOTAL formulas are ignored automatically.
  • Common use: Filter-aware totals, counts, and averages in reports and tables.
Tactical Arena
Select Scenario:
Share SUBTOTAL Function!

Tell your friends about this post

Discussion

ExcelClash is an interactive platform designed to level up your Excel skills through real-world exercises and challenges. Sharpen your logic, solve real spreadsheet problems, and learn faster.

© 2026 ExcelClash, Inc. All rights reserved.