To add subtotals and a grand total in Excel, first sort your data so the rows you want grouped sit together, then use Data > Subtotal to insert automatic subtotals and a grand total in one pass. If you prefer manual control, use the SUBTOTAL function in each group and a SUM formula at the bottom. Both methods work in Excel for Microsoft 365, Excel 2021 and 2019; menu labels can differ slightly by version and region.

What You'll Need

  • Excel for Microsoft 365, Excel 2021, Excel 2019 or Excel for Mac with the Data tab available.
  • A table of data with one text column to group by (for example Category or Region) and at least one numeric column to total.
  • Clean data: no blank rows inside the range and a single header row at the top.

Step-by-Step

  1. Prepare the data. Make sure every column has a header in row 1 and there are no blank rows or columns inside the data. Select any cell inside the range.
  2. Sort by the group column. Go to Data > Sort, choose the column you want to group by (for example Category) in the Sort by box, and click OK. Subtotals only work correctly when matching rows are next to each other.
  3. Open the Subtotal tool. With a cell still selected in the data, go to Data > Subtotal. (On some versions it sits in the Outline group of the Data tab.)
  4. Set the grouping. In the "At each change in" dropdown, pick your group column. In "Use function", choose Sum. In "Add subtotal to", tick the numeric column(s) you want totalled.
  5. Include the grand total. Leave the "Replace current subtotals" box ticked and make sure "Summary below data" is ticked. Click OK. Excel inserts a subtotal row after each group and a Grand Total row at the bottom.
  6. Collapse or expand. Use the outline buttons (1, 2, 3) at the left edge to show only grand totals (1), subtotals (2) or all rows (3).
  7. Manual alternative: If you do not want Excel's outline rows, type =SUBTOTAL(9,B2:B10) under each group (9 means SUM) and =SUM(B2:B20) or =SUBTOTAL(9,B2:B20) at the bottom for the grand total. SUBTOTAL ignores rows already produced by other SUBTOTAL formulas, which prevents double counting.
  8. Convert to a table if you prefer. Select the data and press Ctrl+T (Cmd+T on Mac), tick "My table has headers", then use Table Design > Total Row to add a grand total row. Note that a table's Total Row gives one total, not per-group subtotals; use the Subtotal tool or SUBTOTAL formulas for grouped subtotals.

Common Mistakes

  • Not sorting first. If rows for the same category are scattered, Excel creates a separate subtotal for each block instead of one per category.
  • Using SUM instead of SUBTOTAL inside grouped data. A plain SUM that spans subtotal rows counts them twice and inflates the grand total.
  • Leaving blank rows. A blank row ends the range, so rows below it are ignored.
  • Running Subtotal twice without replacing. If "Replace current subtotals" is unticked, you get nested subtotals that are hard to read.
  • Totalling text columns. The Sum function returns 0 for text; check that the column contains numbers, not numbers stored as text.

Tips

  • Use function number 9 in SUBTOTAL for SUM, 1 for AVERAGE, 2 for COUNT and 3 for COUNTA.
  • Keep a backup copy before running Data > Subtotal; removing subtotals later is done with Data > Subtotal > Remove All, but it is easier to start from a clean copy.
  • Format subtotal rows in bold or a light fill so they stand out when printed.
  • If you add rows after creating subtotals, re-run the Subtotal command so the grand total includes them.

Troubleshooting

  • Grand total is wrong or doubled: check for SUM formulas that include subtotal rows. Replace them with SUBTOTAL or adjust the range to exclude subtotal rows.
  • No subtotals appear: confirm the data is sorted by the group column and that the "At each change in" box matches that column's header.
  • Subtotal rows show 0: the numeric column may be formatted as text. Select it, use Data > Text to Columns > Finish, or convert with VALUE.
  • Outline buttons missing: go to File > Options > Advanced and tick "Show outline symbols if an outline is applied" (label wording varies by version).
  • Subtotal command greyed out: click a single cell inside the data range first; the command is disabled when a whole sheet or multiple sheets are selected.

Frequently Asked Questions

What is the difference between SUBTOTAL and SUM?

SUM adds every cell in the range, including other subtotal rows. SUBTOTAL with function number 9 adds only the visible detail rows and ignores nested SUBTOTAL results, so it is safer for grouped data.

Can I add subtotals without sorting?

Not reliably with Data > Subtotal, because it groups by changes in the column value. Sort first, or use SUMIF/SUMIFS formulas keyed to each category instead.

How do I remove subtotals and the grand total?

Select a cell in the data, go to Data > Subtotal and click Remove All. This deletes the subtotal and grand total rows but keeps your original data.

Does the grand total update when I add rows?

Only if the new rows fall inside the range used by the grand total formula or if you re-run Data > Subtotal. A table's Total Row expands automatically when you add rows to the table.

Can I subtotal more than one column at once?

Yes. In the Subtotal dialog, tick each numeric column under "Add subtotal to". Each gets its own subtotal and grand total.

Why does my grand total differ from the sum of the subtotals?

Usually because a SUM formula includes the subtotal rows. Switch to SUBTOTAL, or restrict the grand total range to detail rows only.