Tutorial

SUBTOTAL Formula in Excel: Subtotals That Respect Filters (Guide)

SUBTOTAL formula in Excel explained: function numbers 1–11 vs 101–111, filtered totals that stay correct, and step-by-step analyst examples with fixes.

Anuj SainiSep 8, 20267 min read

The SUBTOTAL formula in Excel exists for one reason: SUM lies to filtered views. Filter a sales table to the West region and =SUM(B2:B500) still shows the all-India total, sitting above visibly Western rows like a confident wrong answer. SUBTOTAL recomputes over exactly the rows the viewer sees, which makes it the correct total for every working sheet with filters. It builds on filter hygiene and complements pivot table summaries for the cases where detail rows must stay visible.

On the Data Analyst Roadmap, SUBTOTAL is the moment Excel stops being a calculator and starts being a query surface: totals that respond to filters are the spreadsheet version of WHERE clauses.


Two SUBTOTAL families: 1–11 ignore filters only, 101–111 also ignore hidden rows

Picking 9 when you need 109 is the most common SUBTOTAL bug. If anyone manually hides rows in the sheet, only the 101–111 family keeps the total honest.


SUBTOTAL Formula in Excel: Syntax and How It Works

Per Microsoft Support: SUBTOTAL:

excel
=SUBTOTAL(function_num, ref1, [ref2], ...)
ArgumentRequiredWhat it does
function_numYesNumber selecting the aggregation (9 = SUM, 1 = AVERAGE, 2 = COUNT, 3 = COUNTA, 103 = COUNTA visible-only)
ref1, ...YesOne or more ranges to aggregate (for example $B$2:$B$500)

The essential function numbers:

function_numAggregates asHidden-row behavior
1 / 101AVERAGE1 skips filtered rows; 101 also skips manually hidden rows
2 / 102COUNT (numbers)Same split as above
3 / 103COUNTA (non-blank)Same split as above
4 / 104MAXSame split as above
5 / 105MINSame split as above
9 / 109SUMSame split as above

Memorise just two: 109 (the filter-proof SUM for money columns) and 103 (the filter-proof row counter). Two further properties matter. SUBTOTAL ignores nested SUBTOTALs, so section subtotals plus a grand total never double-count. And SUBTOTAL only responds to row visibility — hidden columns are still included, and it cannot see rows hidden by an outline collapse differently from manual hiding (both count as hidden for the 101–111 family).

Step-by-Step Example: Region-Filtered Revenue Totals

A 500-row order table: order ID in A, revenue in B, region in C. Leadership filters by region all day and needs totals they can trust:

Step 1 — replace the naive total in B502:

excel
=SUBTOTAL(109, $B$2:$B$501)

Filter column C to "West" and this cell shows West revenue only. The equivalent =SUM($B$2:$B$501) would keep showing the national figure — open both side by side once and the difference converts every skeptic.

Step 2 — add a visible-order counter in A502:

excel
=SUBTOTAL(103, $A$2:$A$501)

103 counts non-blank visible cells, so it reads "37 of 500 orders" under any filter combination. Pair it with the total for a self-describing header: West, 37 orders, ₹ figure — all three always consistent because all three respect the same filter.

Step 3 — layer section subtotals without fear. Monthly subtotal rows inside the range use the same function:

excel
=SUBTOTAL(109, $B$2:$B$45)

The grand total in B502 skips these nested SUBTOTAL cells automatically. With SUM, each section total would be counted twice — once as detail, once as subtotal — inflating the grand figure. This nesting behavior is also why SUBTOTAL is the safe choice inside structured working sheets that mix detail and subtotal rows.

Step 4 — add a visible-average for the KPI strip:

excel
=SUBTOTAL(101, $B$2:$B$501)

Average order value over visible rows only. A filtered average built on AVERAGE would divide the visible sum by the full row count, silently dragging the metric down — the kind of error that survives review because the number looks reasonable.

Common Mistakes and Fixes

Using 9 where the sheet needs 109

=SUBTOTAL(9, ...) ignores filtered-out rows but includes manually hidden rows. Analysts hide scratch rows by hand constantly, so a 9-based dashboard total quietly absorbs rows the viewer cannot see. Default to the 101–111 family (109, 103, 101) in any sheet humans touch, and reserve 1–11 for programmatically filtered extracts.

The second mistake is pointing SUBTOTAL at a range that excludes new rows. Paste 50 orders below row 501 and every SUBTOTAL still ends at 501. Convert the data to an Excel Table (Ctrl+T) so references extend automatically, or leave a buffer and audit the range monthly — the data cleaning guide covers Table-structured references as the durable fix.

SUBTOTAL cannot rank filtered rows — combine it with a helper

Analysts often want "rank within the filtered set." RANK evaluates hidden rows too, so the workaround is a SUBTOTAL-driven helper: =SUBTOTAL(103, $A$2:A2) produces a visible-only running count down the column, which you can then use as a dense rank proxy. See the RANK guide for the unfiltered mechanics.

SUBTOTAL Formula in Excel vs Other Totals

Feature / Criteria

Choose SUBTOTAL when the sheet is a working surface — filters change, rows hide, and the totals must track what is on screen. Keep SUM for genuinely static ranges (assumptions blocks, checksum cells). Graduate to pivot tables when the audience needs cross-tabbed summaries rather than a filtered detail view.

When to Use the SUBTOTAL Formula in Excel in Analyst Work

Self-updating KPI strips. A three-cell header — visible order count (103), revenue (109), average order value (101) — turns any filtered extract into a live dashboard. Stakeholders filter freely and every number stays internally consistent, which is precisely the "is the answer right?" bar a senior analyst holds.

Audited section reporting. Monthly subtotal rows plus a grand total, all SUBTOTAL-based, give section and overall figures that cannot double-count. Finance reviewers can trace any total to its rows without wondering whether a SUM swallowed a subtotal.

Filter-aware data quality checks. =SUBTOTAL(103, ...) on a key column instantly shows how many non-blank keys survive the current filter — a one-cell completeness check during data cleaning that updates as you drill. When the count drops unexpectedly under a filter, you have found either a data gap or a filter mistake, both worth knowing before the analysis ships.


Master Excel for Data Analysis

Learn Excel formulas, pivot tables, and dashboards with free, project-based courses.

Start Free Excel Course

Frequently Asked Questions

What is the SUBTOTAL formula in Excel?

The SUBTOTAL formula in Excel is =SUBTOTAL(function_num, ref1, ...). The function_num selects the aggregation (9 = SUM, 1 = AVERAGE, 103 = COUNTA ignoring hidden rows), and unlike SUM it can exclude filtered-out and manually hidden rows.

What is the difference between SUBTOTAL 9 and 109 in Excel?

SUBTOTAL 9 sums all values except rows hidden by a filter, but still includes manually hidden rows. SUBTOTAL 109 excludes both filtered-out and manually hidden rows. Use 109 for dashboards where users hide rows by hand.

Why use the SUBTOTAL formula in Excel instead of SUM?

SUM always totals every row, so a filtered 'West region total' still shows the all-region number — a classic wrong-answer bug. SUBTOTAL recomputes over visible rows only, so the total always matches what the viewer sees.

Does SUBTOTAL ignore other SUBTOTALs to avoid double counting?

Yes. SUBTOTAL skips cells that themselves contain SUBTOTAL formulas, so a grand total over a range that already has section subtotals counts each value once. SUM would double-count them.

How does the SUBTOTAL formula in Excel relate to pivot tables?

Both aggregate visible data, but SUBTOTAL keeps the detail rows in place with live totals alongside them, while pivot tables reshape data into a summary. Use SUBTOTAL for working sheets and pivots for presentation summaries.

Anuj Saini

Written by

Anuj SainiFounder & Lead Instructor

Founder at Topfolio with 6+ years in data & analytics across JPMC, Ultrahuman, and high-growth startups. Sat on hiring panels, reviewed 500+ resumes, and writes practical SQL & data guides.