Insert Subtotals in Google Sheets: 2 Ways

How-to basics · Updated November 23, 2026

To insert subtotals in Google Sheets, use the SUBTOTAL function (e.g., =SUBTOTAL(9,B2:B10)) or apply the built-in Data > Pivot table feature. The SUBTOTAL function is the direct equivalent of Excel’s Subtotal command, while a pivot table gives you grouped subtotals with totals automatically. This guide covers both methods, plus sorting, filtering, and common pitfalls.

What the SUBTOTAL Function Does

The SUBTOTAL function calculates a summary (sum, average, count, etc.) for a range, but it ignores rows hidden by a filter. That is its key advantage over SUM: if you filter your data, SUBTOTAL recalculates to show only visible rows. The function uses a numeric code to tell it which operation to perform:

  • 1 – AVERAGE
  • 2 – COUNT
  • 3 – COUNTA
  • 4 – MAX
  • 5 – MIN
  • 9 – SUM
  • 10 – VAR
  • 11 – VARP

For example, with sales amounts in B2:B10, =SUBTOTAL(9,B2:B10) returns the sum of that range. The result updates automatically when you filter the sheet. Note that codes 101–111 (e.g., 109 for SUM) ignore manually hidden rows as well as filtered rows, but codes 1–11 only ignore filtered rows.

How to Add Subtotals Manually (Step-by-Step)

Google Sheets does not have a one-click “Subtotal” button like Excel’s Data > Subtotal. You must add the subtotal rows yourself. Here is the standard workflow:

  1. Sort your data by the column you want to group by (e.g., Region). Select the entire data range, then click Data > Sort range and choose the column.
  2. Insert a blank row after each group. Right-click the row number (e.g., row 5) and choose Insert 1 above or Insert 1 below.
  3. In the blank row’s cell for the numeric column, type =SUBTOTAL(9,B2:B4) (adjust the range to cover that group’s rows).
  4. Label the subtotal row in the first column, e.g., “Region A Subtotal”.
  5. Repeat for each group. For a grand total, add a final row with =SUBTOTAL(9,B2:B100) covering all data rows.

This is tedious for many groups. A pivot table is usually faster and less error-prone.

Using a Pivot Table for Automatic Subtotals

A pivot table groups your data and shows subtotals and grand totals without manual rows. To create one:

  1. Select your data range (include headers).
  2. Click Insert > Pivot table. Choose “New sheet” or “Existing sheet”.
  3. In the Pivot table editor (right side), drag the grouping column (e.g., Region) to Rows.
  4. Drag the numeric column (e.g., Sales) to Values. It defaults to SUM.
  5. By default, each group shows a subtotal row, and the pivot table shows a grand total at the bottom.

To change the subtotal type, click the value field (e.g., “SUM of Sales”) and choose Summarize by – options include AVERAGE, COUNT, MAX, MIN. To turn off grand totals, go to the pivot table editor under Totals and uncheck “Show grand totals”. Pivot tables are the recommended method for large datasets because they update automatically when you add or change data.

Subtotals with Filter Views vs. Manual Rows

If you use Data > Create a filter or a filter view, SUBTOTAL formulas placed in a dedicated summary area (not inside the data range) will recalculate based on visible rows. For example, with data in A1:C100 and a filter applied, put =SUBTOTAL(9,C2:C100) in cell E1 to see the sum of visible rows only. This is a clean way to get a live subtotal without inserting rows. However, this only gives you a single total, not per-group subtotals. For per-group subtotals that respond to filters, you need either a pivot table (which ignores filters by default) or a combination of SUBTOTAL and helper columns – the latter is complex and rarely worth it.

Common Problems and How to Fix Them

Here are frequent issues users hit when inserting subtotals:

  • Subtotal rows are included in other subtotal ranges. If you insert a subtotal row inside the range of another SUBTOTAL formula, you get double counting. Always check that each subtotal range covers only original data rows, not other subtotal rows.
  • Sorting breaks group order. If you add subtotals manually and later sort the sheet, the subtotal rows move with the data and ruin the layout. Use a pivot table if you need to re-sort frequently.
  • Filter hides subtotal rows. When you filter a range that includes manual subtotal rows, those rows may disappear. Keep subtotal rows outside the filtered range, or use a pivot table.
  • Wrong function code. Using =SUBTOTAL(9,...) for sum is correct, but many people accidentally use 9 for average (which is code 1). Double-check the code list.
  • Pivot table not updating. Pivot tables in Google Sheets refresh automatically when the source data changes, but if you add new rows outside the original range, you must update the range in Data > Pivot table and edit the “Data range”.

Subtotals vs. SUMIF and QUERY

For grouped subtotals that you want to display in a separate table (not inline), SUMIF or QUERY are better than manual subtotal rows. For example, with categories in A2:A20 and amounts in B2:B20, =SUMIF(A2:A20,"Electronics",B2:B20) gives the total for one category. To get all categories at once, use =QUERY(A2:B20,"select A, sum(B) group by A label sum(B) 'Total'",1) – this returns a two-column table with each category and its subtotal. Unlike a pivot table, QUERY is a formula that updates live and can be placed anywhere. Choose SUMIF for a single condition, QUERY for multiple groups or more complex aggregation, and a pivot table for interactive analysis with filtering and drill-down.

Frequently Asked Questions

Does Google Sheets have an automatic Subtotal button like Excel? No. Excel’s Data > Subtotal command does not exist in Google Sheets. You must use SUBTOTAL formulas manually or create a pivot table. The pivot table is the closest equivalent and is recommended for most users.

Why does my SUBTOTAL formula return 0? The most common cause is that the range contains no numeric values, or the cells are formatted as text. Check that the cells are numbers (not left-aligned text). Also verify the function code – 9 is for SUM, but if you accidentally used 2 (COUNT), it will count cells, not sum them.

Can I use SUBTOTAL with multiple columns? Yes, but each column needs its own SUBTOTAL formula. For example, =SUBTOTAL(9,B2:B10) for column B and =SUBTOTAL(9,C2:C10) for column C. There is no built-in way to subtotal multiple columns in one formula.

How do I add subtotals after sorting without breaking the layout? Use a pivot table. It recalculates automatically when you sort the source data. If you must use manual subtotal rows, sort first, then insert subtotal rows, and avoid re-sorting afterward.

Do subtotals work with filtered data? Yes, SUBTOTAL with codes 1–11 ignores rows hidden by a filter. If you use codes 101–111, it also ignores manually hidden rows. Pivot tables do not respond to filters by default – they always use all rows in the source range.

What is the difference between SUBTOTAL and SUM? SUM adds all cells in a range, including hidden or filtered rows. SUBTOTAL can exclude filtered rows (and optionally manually hidden rows) depending on the code. If you never filter, they return the same result.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.