How to Use the Subtotal Feature in Excel

Excel Subtotal can insert total rows after each group in a sorted list and add a grand total at the bottom. It also creates an outline so you can collapse detail rows and show only summary totals.

Does this affect you?

Use this for Excel for Microsoft 365, Excel 2021, and Excel 2019 on Windows or Mac when a list is sorted by category and needs group totals without hand-built SUM formulas.

Add automatic subtotals to a sorted list

Sort by the grouping column first so Excel knows where each group begins and ends.

  1. Sort the data by the column you want grouped, such as Region.
  2. Click inside the data range.
  3. Open Data > Subtotal.
  4. Set At each change in to the sorted grouping column.
  5. Choose the function, such as Sum, Average, or Count.
  6. Under Add subtotal to, choose the numeric column or columns to total.
  7. Leave Summary below data checked if you want totals after each group.
  8. Click OK.

Excel inserts subtotal rows and a grand total, plus outline buttons in the margin for expanding or collapsing each group.

Use the SUBTOTAL formula directly

Use this when you want a subtotal in one cell without inserting outline rows.

  1. Click an empty cell near the data.
  2. Enter =SUBTOTAL(.
  3. Use a function number such as 9 for Sum, 1 for Average, or 3 for Count non-blank cells.
  4. Add the range, such as B2:B20, and close the formula.
  5. Press Enter.

Unlike a plain SUM, SUBTOTAL ignores rows hidden by filters and avoids double-counting other subtotal rows.

More control

Remove automatic subtotals

Go back to Data > Subtotal and click Remove All. Excel removes the inserted subtotal rows and outline.

Create nested subtotals

Sort by the outer and inner grouping columns first. Run Subtotal for the outer group, then run it again for the inner group with Replace current subtotals unchecked.

Copy visible totals only

Collapse the outline, select the visible rows, then use the visible-cells-only shortcut before copying so hidden detail rows are skipped.

Choose other functions

Common SUBTOTAL function numbers include 9 for Sum, 1 for Average, 2 for counting numbers, 3 for non-blank count, 4 for Max, and 5 for Min.

Sources

  • Microsoft Support – Calculate subtotals and grand totals in a list of data (2025)
  • Microsoft Support – SUBTOTAL function (2025)
  • Microsoft Support – Group or ungroup rows or columns in a worksheet (2024)
Disclosure: This post may contain affiliate links which means I may receive a commission for purchases made through links. I will only recommend products that I have personally used! Learn more on my Private Policy page.
A thoughtful woman reads a newspaper while enjoying coffee at an indoor workspace.

DEALWEEK

SUBSCRIBE AND GET 20% OFF YOUR NEXT ORDER! OFFER ENDS SOON - DON’T MISS OUT!

We don’t spam! Read our privacy policy for more info.

Shopping Cart