SUBTOTAL: The Ultimate Function for Filtered & Hidden Data

Filter a table and SUM keeps counting every row — including the hidden ones. SUBTOTAL fixes this. It is the only native Excel function that automatically ignores filtered-out rows, updating the moment a filter is applied or removed. This guide covers all 11 aggregation types across both function number ranges (1–11 and 101–111), with eight practical examples: filter-aware SUM, COUNT, AVERAGE, MAX and MIN; group subtotals with a grand total that avoids double-counting; the difference between function 9 and 109 when rows are hidden manually; using SUBTOTAL(103) as a per-row visibility indicator for filter-aware conditional sums; Excel Table Total Row integration; AGGREGATE for median, LARGE, and error-tolerant totals; a live KPI dashboard with a “Showing N of M deals” label; and why SUMIF fails on filtered data — and how to fix it.

Filter a table and SUM keeps counting every row — including the hidden ones. Use SUBTOTAL instead and the total updates the moment a filter is applied. SUBTOTAL is the only native Excel function that automatically ignores filtered-out rows. It also optionally ignores manually hidden rows, and it skips nested SUBTOTAL calls so you can safely place it inside a table without double-counting. These three behaviours together make SUBTOTAL the indispensable function for any report built on filtered or structured data.

This guide covers every function number, the difference between the 1–11 and 101–111 ranges, and eight practical examples. You will learn how to build filter-aware totals, counts, and averages, create a running subtotal that ignores hidden rows, detect which rows are visible, and combine SUBTOTAL with structured table references. Each example also shows the equivalent using AGGREGATE — the modern upgrade that handles errors and offers more functions.

Availability: SUBTOTAL is available in all Excel versions, including Microsoft 365, Excel 2024, 2021, 2019, 2016, and earlier. It also works in Google Sheets. AGGREGATE (the extended version) is available from Excel 2010 onward but is not available in Google Sheets.

What Makes SUBTOTAL Different from SUM?

SUM adds every cell in its range, whether visible or not. Filter the table and SUM does not change. SUBTOTAL, by contrast, operates only on the visible rows. It recalculates automatically whenever a filter changes, when rows are hidden manually, or when the display changes for any reason. This makes SUBTOTAL the correct choice for any total that should reflect the current filtered view rather than the full dataset.

SUBTOTAL also has a second key behaviour: it ignores other SUBTOTAL results nested inside its range. Specifically, if column B contains multiple SUBTOTAL formulas — one per group — and a grand total SUBTOTAL at the bottom references all of column B, the grand total does not double-count the group subtotals. This makes SUBTOTAL safe to use in nested grouping structures without needing to carefully exclude the subtotal rows from the grand total range.

What Is the SUBTOTAL Syntax?

=SUBTOTAL(function_num, ref1, [ref2], ...)
ArgumentRequired?What it does
function_numRequiredA number from 1–11 or 101–111 that specifies the aggregation type. Numbers 1–11 ignore filtered rows but include manually hidden rows. Numbers 101–111 ignore both filtered rows and manually hidden rows.
ref1RequiredThe first range of values to aggregate. Accepts up to 254 additional range arguments (ref2, ref3, ...) for aggregating multiple non-contiguous ranges.

What Are the SUBTOTAL Function Numbers?

The function_num argument determines which aggregation SUBTOTAL performs. Numbers 1–11 include manually hidden rows but ignore filtered rows. Numbers 101–111 ignore both — manually hidden rows and filtered rows. In practice, the 1–11 range is used in most formula-based totals. The 101–111 range is more appropriate when rows are hidden by hand (not by filter) and the total should exclude them.

1–11101–111FunctionEquivalent to
1101AVERAGE=AVERAGE of visible rows
2102COUNT=COUNT of visible rows (numbers only)
3103COUNTA=COUNTA of visible rows (non-empty)
4104MAX=MAX of visible rows
5105MIN=MIN of visible rows
6106PRODUCT=PRODUCT of visible rows
7107STDEV=STDEV of visible rows
8108STDEVP=STDEVP of visible rows
9109SUM=SUM of visible rows
10110VAR=VAR of visible rows
11111VARP=VARP of visible rows
Quick memory rule: Add 100 to any function number to also exclude manually hidden rows. Function 9 = SUM ignoring filtered rows. Function 109 = SUM ignoring filtered rows AND manually hidden rows. If you only use AutoFilter and never hide rows manually, both produce the same result.

Examples 1–4: Core SUBTOTAL Patterns

1
Filter-aware total — SUM, COUNT, and AVERAGE that respond to filters

The most common use is replacing SUM, COUNT, and AVERAGE with SUBTOTAL equivalents in a totals row below a filtered table. When a filter is applied, the SUBTOTAL values update immediately to reflect only the visible rows. The SUM equivalent is function 9, COUNT is function 2, and AVERAGE is function 1.

Region
Sales rep
Revenue
Visible?
North
Alice
4,200
✓ Visible
South
Bob
3,150
✕ Filtered out
North
Carol
5,800
✓ Visible
East
Dave
2,900
✕ Filtered out
North
Eve
6,100
✓ Visible
TOTALS
16,100
3 visible rows
Data in A2:C100. Filter applied: Region = "North" (3 rows visible). Filter-aware SUM (function 9): SUM would return 22,150 (all rows). SUBTOTAL returns 16,100 (visible only). =SUBTOTAL(9, C2:C100) → 16,100 (sum of visible rows only) Filter-aware COUNT — how many rows are currently visible: =SUBTOTAL(2, C2:C100) → 3 (three rows visible after filter) Filter-aware AVERAGE: =SUBTOTAL(1, C2:C100) → 5,367 (average of the three visible rows: 16,100 / 3) Filter-aware MAX and MIN: =SUBTOTAL(4, C2:C100) → 6,100 (highest revenue in visible rows) =SUBTOTAL(5, C2:C100) → 4,200 (lowest revenue in visible rows)
2
Group subtotals — nested SUBTOTAL without double-counting

In grouped reports, each group has its own subtotal row and a grand total at the bottom covers the entire column. If you use SUM for both levels, the grand total double-counts the group subtotals. SUBTOTAL prevents this — it automatically skips any SUBTOTAL result nested inside its range. Consequently, the grand total SUBTOTAL can safely reference the entire column including the subtotal rows.

Layout: Rows 2–6: North region data. Row 7: North subtotal. Rows 8–11: South region data. Row 12: South subtotal. Row 14: Grand total covering C2:C12 (includes subtotal rows 7 and 12). North subtotal in C7: =SUBTOTAL(9, C2:C6) → 26,300 (sum of North rows) South subtotal in C12: =SUBTOTAL(9, C8:C11) → 18,750 (sum of South rows) Grand total in C14 — references entire column including rows 7 and 12: SUBTOTAL skips the C7 and C12 SUBTOTAL cells automatically. SUM(C2:C12) would be 26,300 + 18,750 + 26,300 + 18,750 = wrong. SUBTOTAL(9, C2:C12) correctly returns 45,050 = 26,300 + 18,750. =SUBTOTAL(9, C2:C12) → 45,050 (correct grand total without double-counting)
3
Manually hidden rows — function 109 vs function 9

Function numbers 1–11 respect AutoFilter but include manually hidden rows. Function numbers 101–111 exclude both filtered and manually hidden rows. This distinction matters when rows are hidden via Home → Format → Hide Rows or via grouping and collapsing. In those cases, function 9 still counts the hidden rows while function 109 ignores them.

Row
Value
Status
Row 2
1,000
Visible
Row 3
2,000
Manually hidden
Row 4
3,000
Visible
SUBTOTAL 9
6,000
Includes hidden row
SUBTOTAL 109
4,000
Excludes hidden row
Row 3 is hidden manually (not by filter). A2:A4 = {1000, 2000, 3000}. Function 9 — ignores filtered rows, includes manually hidden rows: =SUBTOTAL(9, A2:A4) → 6,000 (includes row 3 even though it is manually hidden) Function 109 — ignores both filtered rows and manually hidden rows: =SUBTOTAL(109, A2:A4) → 4,000 (excludes row 3 because it is manually hidden) Typical use cases for each range: Function 9 — totals rows in a table with AutoFilter. Most common. Function 109 — dashboards where rows are hidden by grouping or outline level. Also useful when data rows are conditionally hidden by VBA.
4
Detecting visible rows — identify which rows survive a filter

SUBTOTAL with function 3 (COUNTA) on a single row returns 1 if that row is visible and 0 if it is filtered out. This per-row indicator is the foundation of many filter-aware formulas. Specifically, you can use it to build a sequential row number that resets with the filter, flag visible rows for conditional formatting, or feed it into SUMPRODUCT for conditional aggregation on visible rows.

A2:A100 = any column in the data table. Helper column B2 — enter this formula and copy down to B100. Returns 1 for visible rows, 0 for filtered-out rows. =SUBTOTAL(103, A2) → 1 if row 2 is visible, 0 if filtered out Sequential row number for visible rows only: Sums the B column from the first visible row to the current row. Produces 1, 2, 3... for visible rows only — skipping hidden ones. =SUMPRODUCT(=SUBTOTAL(103, OFFSET($A$2, ROW($A$2:A2)-ROW($A$2), 0))) → Running count of visible rows up to and including the current row Sum visible rows that also meet an additional condition: C2:C100 = values. A2:A100 = category. Only sum visible rows where A = "North". SUMPRODUCT multiplies the visibility indicator by the condition. =SUMPRODUCT( (=SUBTOTAL(103, OFFSET(A2, ROW(A2:A100)-ROW(A2), 0))), (A2:A100="North"), C2:C100 ) → Sum of C values that are both visible and in the North region

Examples 5–8: Applied SUBTOTAL Techniques

Excel Tables, AGGREGATE, and Dynamic Dashboards

5
SUBTOTAL in Excel Tables — structured references and Total Row

When you format data as an Excel Table (Ctrl+T), turning on the Total Row automatically inserts SUBTOTAL formulas. The Total Row dropdown lets you choose SUM, COUNT, AVERAGE, and so on — and Excel uses the appropriate SUBTOTAL function number behind the scenes. Additionally, table references adjust automatically when new rows are added, so the SUBTOTAL range never needs manual updating.

Table name: SalesData. Column headers: Region, SalesRep, Revenue. Total Row enabled via Table Design → Total Row checkbox. Excel inserts this automatically in the Total Row Revenue cell: Function 109 is the default for Total Row — ignores both filter and hidden rows. =SUBTOTAL(109, [Revenue]) → Sum of Revenue column, filter-aware, auto-expands with table Manual SUBTOTAL using structured table references (outside the table): Use the table column name in square brackets — the range auto-adjusts. =SUBTOTAL(9, SalesData[Revenue]) → Same filter-aware sum using structured reference Count non-blank reps in visible rows — COUNTA (function 3): =SUBTOTAL(3, SalesData[SalesRep]) → Count of visible non-empty SalesRep cells Average revenue per visible rep — AVERAGE (function 1): =SUBTOTAL(1, SalesData[Revenue]) → Average of visible Revenue values, updates with filter
6
AGGREGATE — the modern upgrade with error handling and more functions

AGGREGATE is the extended version of SUBTOTAL, available from Excel 2010. It adds two major capabilities that SUBTOTAL lacks. First, it can ignore error values in the range — so #DIV/0! or #VALUE! in one cell does not break the total. Second, it supports additional functions that SUBTOTAL does not include: LARGE, SMALL, MEDIAN, PERCENTILE, and RANK. Furthermore, AGGREGATE accepts an options argument that controls exactly which rows to ignore.

AGGREGATE syntax: =AGGREGATE(function_num, options, ref1, [k]) function_num 1–19 (AVERAGE, COUNT, ... PERCENTILE, LARGE, SMALL, etc.) options: 0=nothing extra, 1=ignore hidden rows, 2=ignore errors, 3=ignore hidden+errors, 4–7=also ignore nested SUBTOTAL/AGGREGATE A2:A100 = values with some #DIV/0! errors. SUM ignoring filtered rows AND errors — AGGREGATE equivalent of SUBTOTAL 9: options=5 ignores hidden rows and error values. =AGGREGATE(9, 5, A2:A100) → Sum of visible non-error values (errors are skipped) MEDIAN of visible rows — not available in SUBTOTAL: function_num 12 = MEDIAN. =AGGREGATE(12, 5, A2:A100) → Median of visible rows only LARGE of visible rows — k-th largest among visible values: function_num 14 = LARGE. k is the 4th argument. =AGGREGATE(14, 5, A2:A100, 3) → 3rd largest value among visible rows PERCENTILE of visible rows — 90th percentile among visible values: function_num 18 = PERCENTILE.INC. k = 0.9 for 90th percentile. =AGGREGATE(18, 5, A2:A100, 0.9) → 90th percentile of visible rows
7
Dynamic dashboard — filter-aware KPI cells using SUBTOTAL

A management dashboard built on SUBTOTAL updates all KPI cells the moment a slicer or filter changes. Each metric references the same table column with a different function number. Adding a progress bar or conditional formatting to the KPI cells makes the changes immediately visible. No VBA, no Power Query refresh — the dashboard is entirely formula-driven.

SalesData table filtered by Region slicer or AutoFilter dropdown. All formulas below update automatically when the filter changes. KPI 1 — Total revenue (filtered): =SUBTOTAL(9, SalesData[Revenue]) KPI 2 — Number of visible deals: =SUBTOTAL(2, SalesData[Revenue]) KPI 3 — Average deal size (filtered): =SUBTOTAL(1, SalesData[Revenue]) KPI 4 — Largest single deal (filtered): =SUBTOTAL(4, SalesData[Revenue]) KPI 5 — % of total (filtered revenue / full revenue): D2 = SUBTOTAL result. E2 = SUM of full column (no SUBTOTAL). Shows what fraction of total revenue the current filter represents. D2 / SUM(SalesData[Revenue]) → e.g. 34% (filtered region is 34% of total revenue) Label showing filter status — "Showing 3 of 47 deals": SUBTOTAL(2) = visible count. COUNT = total count (unfiltered). "Showing " & =SUBTOTAL(2, SalesData[Revenue]) & " of " & COUNT(SalesData[Revenue]) & " deals" → "Showing 3 of 47 deals" (updates when filter changes)
8
SUBTOTAL vs SUMIF — filter-aware conditional sum

SUMIF and COUNTIF do not respect filters. They count and sum all matching rows, including filtered-out ones. Consequently, combining a filter with SUMIF gives misleading results — the SUMIF total does not change when the filter changes. Two approaches solve this problem: SUMPRODUCT with the SUBTOTAL(103) visibility indicator, or using AGGREGATE for the aggregation and applying the condition separately.

A2:A100 = Region. B2:B100 = Product. C2:C100 = Revenue. Filter is active (e.g. showing only Q1 rows by date filter in column D). Problem: SUMIF ignores the active filter entirely. =SUMIF(A2:A100,"North",C2:C100) — returns North total for ALL rows. Solution 1: SUMPRODUCT with visibility helper. Create helper column E2:E100 = SUBTOTAL(103, A2), copy down. Then use SUMPRODUCT to combine visibility with the condition. =SUMPRODUCT(E2:E100, (A2:A100="North"), C2:C100) → Sum of North revenue for visible rows only Solution 2: Inline visibility without helper column. OFFSET generates per-row SUBTOTAL(103) values on the fly. Slower on large data but needs no helper column. =SUMPRODUCT( (=SUBTOTAL(103, OFFSET(A2, ROW(A2:A100)-ROW(A2), 0))), (A2:A100="North"), C2:C100 ) → Same filter-aware North revenue sum, no helper column needed Two-condition filter-aware sum (North AND Product = "Widget"): Add a second condition to the SUMPRODUCT. =SUMPRODUCT( E2:E100, (A2:A100="North"), (B2:B100="Widget"), C2:C100 ) → Sum of North Widget revenue in visible rows only

Common Issues and How to Fix Them

SUBTOTAL does not change when I apply a filter

SUBTOTAL only responds to AutoFilter (Data → Filter or Table filters). It does not respond to manual colour-based filtering, slicer-only filtering on ranges that are not tables, or filtering applied via VBA on a different sheet. If the filter is an AutoFilter and SUBTOTAL still does not update, check that Automatic Calculation is enabled: Formulas → Calculation Options → Automatic. Additionally, confirm the SUBTOTAL range overlaps with the filtered rows — a range that accidentally excludes some rows will not change even if those rows are filtered.

SUBTOTAL and SUM give different results even without a filter

SUBTOTAL skips nested SUBTOTAL values inside its range. If the range contains subtotal rows from a grouped structure, SUBTOTAL deliberately excludes them — this is the intended behaviour for grand totals. If you need SUM to include all values including other SUBTOTAL results, use SUM instead. Conversely, if the results differ and you did not expect them to, inspect the range for hidden SUBTOTAL rows that SUBTOTAL is skipping.

SUBTOTAL with errors — the result shows #VALUE! or #DIV/0!

SUBTOTAL propagates errors from the cells in its range. If one cell in the range contains #DIV/0!, #VALUE!, or any other error, SUBTOTAL returns that error. The fix is to switch to AGGREGATE with options = 6 (ignore errors) or options = 7 (ignore hidden rows and errors). For example, =AGGREGATE(9, 7, C2:C100) sums visible rows and skips any error cells without returning an error itself.

SUBTOTAL does not work across multiple sheets: SUBTOTAL cannot aggregate across different worksheets. A formula like =SUBTOTAL(9, Sheet1:Sheet3!C2:C100) returns an error. If you need filter-aware totals from multiple sheets, consolidate the data onto one sheet first — either manually, via Power Query, or using 3D-reference SUM formulas at a different level. AGGREGATE has the same limitation.

Frequently Asked Questions

  • What is the SUBTOTAL function in Excel?+
    SUBTOTAL is a multi-purpose aggregation function that operates only on visible (non-filtered) rows. It accepts a function number (1–11 or 101–111) that specifies whether to SUM, COUNT, AVERAGE, MAX, MIN, or apply other operations. Unlike SUM or AVERAGE, SUBTOTAL automatically ignores rows that have been hidden by AutoFilter. It also skips any other SUBTOTAL results nested inside its range, making it safe for grouped reports with subtotals and grand totals. In Excel Tables, the Total Row uses SUBTOTAL by default.
  • What is the difference between SUBTOTAL 9 and SUBTOTAL 109?+
    Both calculate SUM and both ignore rows hidden by AutoFilter. The difference is manual hiding. SUBTOTAL 9 includes rows that were hidden manually via Home → Format → Hide Rows or by collapsing a group outline. SUBTOTAL 109 excludes those manually hidden rows as well. For most filtered tables, the two produce identical results because rows are hidden by filter, not manually. Use 109 when rows are hidden by grouping or outline and you want the total to reflect only the displayed rows.
  • Why does SUMIF not work with filtered data?+
    SUMIF evaluates all rows in its range regardless of filter status. It has no awareness of which rows are currently visible. Consequently, applying a filter does not change the SUMIF result. To get a filter-aware conditional sum, use SUMPRODUCT combined with a SUBTOTAL(103) visibility helper column. The helper column returns 1 for visible rows and 0 for filtered-out rows. Multiplying SUMPRODUCT by that helper effectively limits the sum to visible rows only. Alternatively, AGGREGATE handles many aggregations on visible rows, though it does not support condition-based filtering natively.

More Questions About SUBTOTAL

  • What is the difference between SUBTOTAL and AGGREGATE?+
    SUBTOTAL supports 11 aggregation functions and cannot handle errors in the range. AGGREGATE supports 19 functions — including MEDIAN, LARGE, SMALL, PERCENTILE, and RANK — and can optionally ignore error values. AGGREGATE also offers more granular control over which rows to ignore via the options argument. The trade-off is availability: SUBTOTAL works in all Excel versions and Google Sheets, while AGGREGATE requires Excel 2010 or later and does not work in Google Sheets. For most everyday filter-aware totals, SUBTOTAL is sufficient. Use AGGREGATE when you need error tolerance or functions beyond SUBTOTAL’s 11.
  • Can SUBTOTAL work with multiple ranges?+
    Yes. SUBTOTAL accepts up to 255 range arguments: =SUBTOTAL(9, A2:A50, C2:C50, E2:E50). This sums all three columns counting only visible rows in each. However, all ranges must be on the same sheet — SUBTOTAL cannot span multiple worksheets. The multiple-range capability is useful when non-contiguous columns need to be aggregated together in one formula. Note that the ranges should not overlap, as overlapping ranges cause values in the overlap to be counted multiple times.
  • Does SUBTOTAL work in Google Sheets?+
    Yes, SUBTOTAL works in Google Sheets with the same function numbers and syntax as Excel. It responds to filters applied via Data → Create a Filter. However, AGGREGATE is not available in Google Sheets — it is an Excel-only function. If you need median, percentile, or error-ignoring behaviour in Google Sheets with filter awareness, the SUBTOTAL(103) visibility helper combined with SUMPRODUCT is the most reliable workaround.