Skip to content

Insert subtotals and collapse the outline

Subtotals and outlines8 minPremium

Builds on Sort by one or more columns and Total only the rows you can see with SUBTOTAL.

Each month a finance assistant in Hamburg sends her director the expense list with a total under every cost center. Typing those rows by hand takes an hour, and one sort later they're in the wrong places.

How it works

The Subtotal command inserts a total row each time the value in one column changes, so first sort the list by that column to bring each group's rows together. Then click a cell in the list, choose Data > Subtotal and fill in three boxes:

RowAB
1BoxWhat to choose
2At each change inthe column you sorted by
3Use functionSum, Count, Average, Max, Min and others
4Add subtotal tothe columns to total

Excel inserts a total row under each group and a Grand Total at the bottom, all as SUBTOTAL formulas, so the grand total skips the group totals and comes from the detail rows. The outline buttons 1, 2 and 3 appear to the left of the row numbers: 1 shows the grand total only, 2 the group totals as well, 3 every row. The plus and minus buttons open and close one group.

To add a second level, such as a total per rep within each region, sort by both columns, then run Subtotal again for the inner column with Replace current subtotals cleared. Remove All, in the same dialog, takes the subtotals and the outline away.

Example

The assistant sorts the list by Cost center, then chooses At each change in Cost center, Use function Sum, and Add subtotal to Amount.

  1. Step 1: The list is sorted by Cost center, so each group's rows sit together.
  2. Step 2: At each change in Cost center, Excel adds a total row, such as =SUBTOTAL(9,C2:C3) in C4.
  3. Step 3: The Grand Total, =SUBTOTAL(9,C2:C8), skips the two group totals and shows €6,510.
The Subtotal command writes SUBTOTAL formulas. The Grand Total's range takes in the group totals too, and SUBTOTAL skips them, so nothing is counted twice. In C9, =SUBTOTAL(9,C2:C8) returns €6,510.

Common mistakes

  • On an unsorted list, Subtotal starts a new group at every change, so one cost center gets several totals. Sort by the column first.
  • Subtotal isn't available while the active cell is in an Excel table. Convert the table to a range first, with Convert to Range on the Table Design tab.
  • Running Subtotal again with Replace current subtotals ticked removes the first level. Clear it to add a level instead.
  • A copy of a collapsed outline takes the hidden detail rows along. To copy only the totals, select them and use Go To Special > Visible cells only, as in Fill blanks with Go To Special.

In short

  • Sort first, then Data > Subtotal: at each change in the sorted column, a function, and the columns to total.
  • The outline buttons 1, 2 and 3 show the grand total, the group totals, or every row.
  • Clear Replace current subtotals to add a level; Remove All takes the subtotals away.
  • Subtotal works on ranges, not tables.

Practice

Premium

4 exercises: 2 dialogs, 1 quiz question and 1 set of steps.

Practice is part of Premium

Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.