Asset 20 8 2
Does AI recommend your business? Run the free check →

Join 15,000 business owners, marketers and entrepreneurs. The Sunday newsletter you'll be annoyed only arrives once a week.

Article

How to Use the SUBTOTAL Function in Excel: Function Numbers, Hidden Rows and the Data Tab

=SUBTOTAL(function_num, range) totals, averages or counts a list while ignoring any other SUBTOTAL formulas inside the range, so nothing gets counted twice. Use 9 for SUM or 1 for AVERAGE, or 109 and 101 if you want rows you've hidden by hand left out.

Microsoft describes SUBTOTAL as returning a subtotal in a list or database. The syntax is SUBTOTAL(function_num, ref1, ref2, ...), where ref1 is required and you can add more ranges after it. The function number decides what kind of calculation it does.

A quick example

Microsoft's example has four numbers, 120, 10, 150 and 23, in cells A2 to A5.

  • =SUBTOTAL(9,A2:A5) returns 303, the sum.
  • =SUBTOTAL(1,A2:A5) returns 75.75, the average.

So far it looks like SUM and AVERAGE with an extra number. The difference shows up when your data has hidden rows, filters or other subtotals in it.

The SUBTOTAL function numbers

There are 11 calculations, each with two numbers. Here's Microsoft's full list:

FunctionIncludes manually hidden rowsIgnores manually hidden rows
AVERAGE1101
COUNT2102
COUNTA3103
MAX4104
MIN5105
PRODUCT6106
STDEV7107
STDEVP8108
SUM9109
VAR10110
VARP11111

The catch: hidden rows and filtered rows aren't the same

This is the part that confuses people, and Microsoft spells it out. Numbers 1 to 11 include values in rows you've hidden manually. Numbers 101 to 111 leave those rows out. But either way, SUBTOTAL ignores any rows that a filter has removed from view.

So if you filter a list, 9 and 109 give you the same answer, because both skip the filtered-out rows. If you hide rows by right-clicking and choosing Hide, only 109 leaves them out. That's why SUBTOTAL is the formula to put under a filtered list: the total changes as the filter changes, which a plain SUM won't do. If you're new to filters, here's how to filter in Excel.

Two more rules from Microsoft. SUBTOTAL is built for columns of data, so hiding a column doesn't affect a formula like SUBTOTAL(109,B2:G2) that runs across a row. And if the range contains other subtotals, nested inside it, they're ignored to avoid double counting. A 3-D reference across several sheets returns #VALUE!.

To go a step further, try how to use the IF function in Excel.

How to add subtotals with the Data tab

You don't have to type SUBTOTAL formulas yourself. Microsoft says it's generally easier to use the Subtotal command in the Outline group on the Data tab of the desktop app, then edit the SUBTOTAL formulas it creates if you need to. Before you start, make sure each column has a label in the first row, each column holds similar facts, and there are no blank rows or columns in the range.

  1. Sort the column you want to group by: Data tab, Sort and Filter, Sort A to Z.
  2. Go to the Data tab, Outline group, and click Subtotal.
  3. In At each change in, choose the column you sorted.
  4. In Use function, choose the calculation, such as Sum.
  5. In Add subtotal to, tick the columns you want totalled.
  6. Choose whether to add a page break between groups and whether the summary row goes above or below, then click OK.
  7. Use the level buttons to show or hide the detail rows.

CFI's example is a garment maker with T-shirts in five colours and seven sizes, stored across two warehouses. Sort by colour, then run Subtotal with At each change in set to Color, Use function set to Sum, and the units in Warehouse I and Warehouse II ticked. Excel inserts a subtotal row below each colour, and the level buttons 1, 2 and 3 let you collapse the list to just the totals. Grouping rows by hand works differently; here's how to group rows in Excel if that's what you're after.

Work with me

Want AI doing the heavy lifting in your marketing?

I build the systems that handle the boring 80 percent, so you get your week back. Done properly, with the human kept in.

Things that trip people up with the Subtotal command

  • It's greyed out in an Excel table. Microsoft says subtotals aren't supported in tables, so convert the table to a normal range first, which removes table features except the formatting, or use a PivotTable instead.
  • Grand totals come from the detail rows, not from the subtotal rows. So an Average grand total is the average of every detail row, not an average of the subtotals.
  • If you filter data that contains subtotals, the subtotals can disappear from view. Clear all filters to see them again.
  • To add a second level, such as subtotals within subtotals, run the command again with Replace current subtotals cleared.
  • To take them off, open the Subtotal box again and click Remove All.

With automatic calculation switched on, Microsoft says the subtotals recalculate as you edit the detail data, and the list is outlined so you can show or hide the detail.

Related reading: the full answer on how to use SUMPRODUCT in Excel.

My verdict

Use 109, not 9, when you hide rows by hand and want them left out of the total. If you only ever filter, either works. I'd use SUBTOTAL under any list you plan to filter, because it's the one total that stays honest as you change what's showing. And if you're summarising a big table rather than a sorted list, a pivot table is usually the better tool.

Frequently asked questions

What is the difference between SUBTOTAL 9 and 109?

Both sum. 9 includes rows you've hidden manually; 109 leaves them out. Both ignore rows removed by a filter.

Does SUBTOTAL ignore filtered rows?

Yes. Microsoft says SUBTOTAL ignores any rows not included in the result of a filter, whichever function number you use.

Why is the Subtotal button greyed out?

Because the data is in an Excel table. Microsoft says to convert it to a normal range or use a PivotTable.

Does SUBTOTAL double count other subtotals?

No. If the range contains other subtotals, Microsoft says they're ignored to avoid double counting.

How do I remove subtotals in Excel?

Open the Subtotal box on the Data tab again and click Remove All.

Published and maintained by the Lilach Bullock team, covering marketing, AI and business growth.
Your buyers are asking AI who to use. Does it say you?

See for free whether ChatGPT, Claude, Perplexity, Gemini and Google name you, and get the plan to become the answer.

Check my AI visibility →
Sundays only

Get the Sunday newsletter.

One email a week. AI experiments, marketing tactics, and the workflows Lilach is building right now in her own business.

Subscribe free

Let’s get your marketing running on AI.

Book a free 30-minute call

We figure out what you need, where AI fits in, and what working together would look like.

Book the call →

Or take the 30-second calculator

You’ll see the hours and the money quietly leaking out of your week, and the three workflows worth building first.

Take the calculator →

Or grab the free AI resource library

Prompt packs, templates, checklists, and swipe files. The exact tools I build for paying clients. Yours, free.

Get the library →
Keep reading

More from the blog.