SUBTOTAL in Excel Formula

“subtotal in excel formula” comes up constantly, so this page leads with the exact answer, and only then explains the detail. Everything works in Excel on Windows and Mac and maps almost one-to-one to Google Sheets. Copy the answer above and get back to work, or read on to turn a one-off fix into something you never have to look up again.

Exact answer

In Excel: use =SUBTOTAL(9, range) — it runs the calculation that function_num picks (9 is SUM) over the rows still counted: 1–11 skip rows a filter hides, 101–111 also skip rows hidden by hand, so a filtered table's total updates as you filter.

On this page8

Syntax

=SUBTOTAL(function_num, ref1, ...)

Arguments

Argumentrequired / optionalDescription
function_numrequiredWhich calculation to run: 9 sums, 1 averages, 3 counts. Add 100 (109, 101, 103) to also ignore manually hidden rows.
ref1requiredThe range to aggregate. Further ranges can follow.

Related functions

AGGREGATESUMIFCOUNTIF
Annotated stepsExcel
1

Click a cell above or below the data — not inside the filtered range itself.

2

Type =SUBTOTAL( and then the function number: 9 for a sum.

3

Add a comma and select the data range.

4

Press Enter, then apply a filter and watch the total change to match what is on screen.

Ctrl+CthenCtrl+Shift+V+Cthen+Ctrl+VPaste values · WindowsMac

Need it as an auditable file?

Ships inside the linked template — formula-driven, unlocked, audit-ready.

View template

What this does

SUBTOTAL runs one of eleven aggregations, chosen by a number, and — crucially — ignores rows hidden by a filter. That is what makes a filtered table's total honest: a plain SUM keeps totalling rows the filter has removed from view. The function number chooses the operation (9 = SUM, 1 = AVERAGE, 2 = COUNT, 3 = COUNTA, 4 = MAX, 5 = MIN). Adding 100 to it (109, 101 and so on) additionally excludes rows you hid by hand, not just filtered ones. SUBTOTAL also ignores any nested SUBTOTAL inside its own range, so section totals do not get double-counted in a grand total. Most people learn this as a sequence of clicks and forget it by next week; learning it as a pattern instead is what lets you apply it to the next, slightly different version of the problem without starting from scratch. That is the difference this page is trying to make. For “subtotal in excel formula”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected formula change, and only then apply the same setup to the full sheet. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That is what makes a calculation you can defend to a CFO or an auditor useful in real work: repeatable, auditable, and not dependent on memory or luck.

A worked example

Above a filtered sales table, =SUBTOTAL(9, D2:D500) shows the total of just the rows currently visible and recalculates on every filter change. To average only visible rows, =SUBTOTAL(1, D2:D500). To exclude manually hidden rows as well as filtered ones, =SUBTOTAL(109, D2:D500). SUBTOTAL is what makes a filtered report tell the truth, because it totals what the reader can actually see. One habit worth forming early: name the cells that hold your inputs, so the formula reads in plain language instead of a string of cell addresses. A reviewer — or you in three months — can then follow the logic without decoding what B7 and D2 were supposed to mean, which is most of what makes a sheet maintainable.

In Google Sheets

Everything above works in Google Sheets too. Excel and Sheets share the formula syntax used here; only the surrounding menus are arranged differently. That portability is deliberate — learn it once and it follows you between the two tools and across Windows and Mac. Keep this page bookmarked for the next time the same question comes up. Better still, repeat the steps once in your own workbook — doing it yourself is what turns a copied answer into something you remember. If you take one thing from this page on “subtotal in excel formula”, make it the habit rather than the keystrokes: set the problem up with labelled inputs, reference those cells, and let Excel do the recomputing. Bookmark the page for the syntax, but do the example once in a blank sheet and check it against the tool above — five minutes of hands-on practice fixes the method in memory far better than re-reading, and it surfaces the small snags while they are still harmless. After that the technique is genuinely yours: faster than searching for it again, and reliable enough to drop into work that other people depend on.

Common mistakes

  • Using 9 when rows were hidden by hand rather than filtered — 9 still counts those. Use 109 to exclude both kinds.
  • Placing the SUBTOTAL cell inside the filtered range, where the filter can hide the total itself.
  • Reaching for SUBTOTAL when the requirement is a condition rather than a filter; SUMIFS is the right tool for "sum where region = West".

Frequently asked questions

What is the difference between SUBTOTAL and SUM?

SUM totals every row in the range regardless of filtering. SUBTOTAL(9, …) totals only the rows a filter is currently showing.

What do the function numbers mean?

1 AVERAGE, 2 COUNT, 3 COUNTA, 4 MAX, 5 MIN, 6 PRODUCT, 7 STDEV, 8 STDEVP, 9 SUM, 10 VAR, 11 VARP. Add 100 to any of them to also ignore manually hidden rows.

Does SUBTOTAL double-count nested subtotals?

No. It deliberately ignores other SUBTOTAL results inside its range, so a grand total over sections stays correct.

Other ways people ask this

On the way here you may have searched this as “how to use excel subtotal”, “excel formula subtotal”, “excel formula for subtotal” and “how to use subtotals in excel” — it is all the same task, and this page is the single, complete answer to it.

Why do people search for this in so many different ways?

Because the same task has many names. “how to use excel subtotal”, “excel formula subtotal”, “excel formula for subtotal” all point at the one operation explained on this page, which is why they all lead here.