How to Compute Subtotal in Excel: Step-by-Step
In this article
You compute a subtotal in Excel either with the SUBTOTAL function or with Data > Subtotal (called Outline > Subtotal in older versions and on the Mac menu layout). The quickest version: click a cell below your numbers, type =SUM(range) for a plain subtotal, or type =SUBTOTAL(9,range) when you plan to filter or hide rows and want the total to respond. If you have a list with categories and want Excel to insert the subtotals and grouping for you, use Data > Subtotal instead of writing formulas. Menu labels can differ slightly by version, device and region, so look for the closest wording if yours does not match exactly.
What You'll Need
- Microsoft Excel on desktop (Windows or Mac), or Excel for the web. The full Data > Subtotal command is available on desktop; Excel for the web has limited tools, so plan on a desktop if you need automatic grouping.
- A table of numbers you want to add up, ideally with a header row and no blank rows or columns inside the data.
- A category column if you want per-group subtotals (for example a Region or Department column).
- Numbers stored as real numbers, not as text. Left-aligned figures usually mean they were entered or imported as text and will be ignored by SUM.
Step-by-Step
Method 1: A plain subtotal with SUM
- Click the cell where the subtotal should appear. Put it directly below the column of numbers, or leave a row or two of space if you plan to add more entries.
- Type
=SUM(and then select the cells you want to add. You can drag with the mouse, or type a range such asB2:B20. - Close the bracket and press Enter. The cell now shows the total of that range.
- If the number looks wrong, check the Status Bar: select the same range and Excel shows Sum, Average and Count at the bottom of the window. If the Status Bar Sum differs from your formula, part of the range is text or contains an error value.
- Copy the formula to other columns by dragging the fill handle (the small square at the bottom-right of the selected cell) sideways. Relative references adjust automatically, so the same pattern works across columns.
Method 2: SUBTOTAL so the figure respects filters
- Type
=SUBTOTAL(9,and then select your range, for example=SUBTOTAL(9,C2:C100). The 9 means SUM. Use 109 instead of 9 if you also want the result to ignore rows you have manually hidden, not just filtered-out rows. - Press Enter. Apply a filter to your table with Data > Filter, then filter out some rows. The SUBTOTAL cell recalculates to show only the visible rows.
- Add another SUBTOTAL cell for a different range if you want per-section figures, then a final grand total. Crucially, the grand total must also use SUBTOTAL, or a plain SUM will double-count the subtotal rows that sit inside the range.
- To sum only rows that already contain SUBTOTAL formulas and nothing else, use
=SUBTOTAL(9,range)because SUBTOTAL ignores other SUBTOTAL results nested in its range, which is exactly what you want for a grand total.
Method 3: Automatic subtotals with Data > Subtotal
- Sort your list by the category column first (Data > Sort). The command groups rows that are adjacent, so unsorted data produces repeated subtotal blocks for the same category.
- Select any cell inside the data, then go to Data > Subtotal.
- In the dialog, set At each change in to your category column, Use function to Sum, and tick the numeric column under Add subtotal to. Tick Replace current subtotals if you are re-running it so you do not stack duplicates.
- Click OK. Excel inserts a subtotal row for each category and an outline with grouping buttons at the left edge (1, 2, 3) so you can collapse or expand detail.
- Use the outline buttons to view just totals. Level 2 shows subtotals only; level 1 shows the grand total.
- To undo the layout later, go back to Data > Subtotal and click Remove All. This deletes the subtotal rows but keeps your data.
Common Mistakes
- Mixing SUM and SUBTOTAL. If a grand total uses SUM and the range includes subtotal rows, those rows are counted twice. Either keep every total as SUBTOTAL or keep all data rows separate from subtotal rows.
- Leaving blank rows inside the data. Both SUM ranges and the Data > Subtotal command treat a blank row as the end of a block, so part of your list is silently left out.
- Forgetting to sort before Data > Subtotal. The same category appears in several subtotal blocks, which looks like a bug but is just unsorted input.
- Numbers stored as text. Imported values with spaces or apostrophes are ignored. A quick test: if
=SUM(A1:A10)returns 0 despite visible numbers, they are text. Convert them with Data > Text to Columns or by multiplying by 1 in a helper column. - Using 9 when you meant 109. Plain SUBTOTAL(9) still counts rows you manually hid; only 109 ignores both filtered and manually hidden rows.
Tips
- Format your source data as a table (Insert > Table) and use the Total Row option. It builds a SUBTOTAL that adjusts when you filter, and totals survive new rows added to the table.
- Press Alt+= (Windows) to insert an AutoSum formula instantly for the column above.
- Name your ranges (Formulas > Define Name) so totals read like
=SUBTOTAL(9,Revenue)instead of a long cell reference. This makes audits far easier. - If subtotals should react to filters everywhere, use SUBTOTAL throughout the sheet rather than repeatedly deciding between SUM and SUBTOTAL.
- Use 3 instead of 9 inside SUBTOTAL if you want a count of visible rows, which pairs well beside a sum total.
Troubleshooting
If that did not work, check these in order.
- The total shows 0 or is far too small: verify the cells are numbers, not text, and confirm the range actually covers all rows. Select the range and read the Status Bar sum as a quick cross-check.
- The total is far too large: look for a SUM range that overlaps a subtotal row, or duplicated entries created by running Data > Subtotal twice without Replace current subtotals.
- Data > Subtotal is greyed out: the active cell is probably outside the list or the data has blank separating rows. Click inside the block and confirm there are no gaps.
- Grouping buttons vanished: go to Data > Outline and check the outline symbols are enabled in Excel Options > Advanced, under the display options for this worksheet.
- The filter does not change the total: you are using SUM rather than SUBTOTAL. Switch the formula type, or recalculate with F9 to confirm you are looking at fresh values.
- Manual hidden rows are still counted: change 9 to 109.
Frequently Asked Questions
What is the difference between SUM and SUBTOTAL?
SUM adds every cell in a range, hidden or not. SUBTOTAL with 9 adds visible rows only when a filter is active, and 109 also ignores manually hidden rows. SUBTOTAL also skips other SUBTOTAL results, which prevents double counting in grand totals.
Can I subtotal more than one column at once?
Yes. In Data > Subtotal you can tick several numeric columns under Add subtotal to, and Excel inserts one subtotal row per group containing all chosen columns. With formulas, simply copy the SUBTOTAL or SUM formula sideways.
Why does my SUBTOTAL change when I collapse grouped rows?
It should only change when rows are filtered or hidden. If collapsing outline groups changes the figure, check whether the total uses a plain SUM range that includes hidden subtotal rows.
Does SUBTOTAL work in Excel for the web?
The SUBTOTAL function works in Excel for the web. The Data > Subtotal outline command is more limited there, so for the automatic grouping workflow use the desktop app.
Can I subtotal percentages or averages?
Yes. Use function number 1 for AVERAGE instead of 9 for SUM, for example =SUBTOTAL(1,B2:B50). Do not simply add percentages; a subtotal of percentages gives a meaningless figure, so average or recalculate from the underlying values instead.