
Performs a calculation such as SUM or AVERAGE while respecting filtered rows.
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.
SUBTOTAL is useful in list-style models because it can respond to filtered and visible data. That gives it a different role from a plain total: it helps worksheets stay interactive, especially when the visible slice of the data changes over time.
Use SUBTOTAL when the calculation should respond to filtering or hidden-row behavior.
The returned value depends on the function code you choose, such as SUM, AVERAGE, COUNT, MAX, or MIN.
=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.
| 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 |
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.
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.
In cell D1, sum the values in B1:B5 while respecting filtered rows.
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.
In cell D2, count the visible non-empty cells in B1:B5.
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.
In cell D3, average the visible values in B1:B5.
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.
In cell D4, 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.
1-11 include manually hidden rows.101-111 exclude manually hidden rows.SUBTOTAL is most useful when the worksheet view can change. This lesson showed that unlike a normal SUM or AVERAGE, SUBTOTAL can follow the visible rows, which makes it a better fit for filtered reports and table summaries.
The other important idea was the function code. It does two jobs at once: it chooses the type of calculation and it decides how hidden rows are treated. Once you understand that part, SUBTOTAL becomes much easier to use correctly.
SUBTOTAL aggregates data while respecting filtered rows.Tell your friends about this post