Sub topic 6
Expanding ranges and running totals
This chapter assumes you can write a basic formula, fill it down with the fill handle, and tell relative references (B2) from absolute ones ($B$2). It builds on mixed references from the previous chapters and uses one more idea: a range has two ends, and each end can be locked or left free on its own.
A range has two anchors
A range such as B2:B10 is two cell references joined by a colon. Excel adjusts each end separately when you copy or fill the formula. That means you can lock one end and let the other move.
| Range written in C2 | Start | End | Filled down one row |
|---|---|---|---|
| `B2:B10` | relative | relative | `B3:B11` (the whole range slides) |
| `$B$2:$B$10` | absolute | absolute | `$B$2:$B$10` (nothing changes) |
| `$B$2:B2` | absolute | relative | `$B$2:B3` (the range grows) |
The third row is an expanding range. The start stays on the first data row. The end follows the formula down the sheet.
Building a running total
A running total shows the sum of everything from the first row up to the current row. Suppose column B holds monthly sales in B2:B13. Enter this in C2 and fill it down:
C2: =SUM($B$2:B2)
C3: =SUM($B$2:B3)In C2 the range is a single cell, B2. Filling down one row moves the relative end to B3, so C3 adds B2 and B3. By C13 the formula is =SUM($B$2:B13), which adds all twelve months.
The same formula in every row is the main benefit. You don't write a different formula per row, so you can't make a typing mistake in one of them.
Worked example: share of total and running share
Combine an expanding range with a fixed total. With sales in B2:B10, the running total in C and the cumulative share of the grand total in D look like this:
C2: =SUM($B$2:B2)
D2: =C2/SUM($B$2:$B$10)In D2, C2 is relative, so each row uses its own running total. The SUM($B$2:$B$10) part is fully absolute, so every row divides by the same grand total. The last row of column D shows 100%.
Here the two kinds of range sit side by side in one workbook. One grows, and the other stays put. Which one you need depends on the question you are asking: "up to this row" or "all rows."
Other expanding patterns
You can anchor the end instead of the start. For example, =SUM(B2:$B$13) fills down as a "remaining total": row 2 adds everything, and each later row adds less. The relative start moves down while the absolute end stays at the bottom.
The same idea works across columns. To total from January in column B through the current month in a row, lock the column instead:
B3: =SUM($B2:B2)Filled to the right, this becomes =SUM($B2:C2), then =SUM($B2:D2). Only the end column moves.
You can also expand with other functions. =MAX($B$2:B2) gives the highest value seen so far, and =AVERAGE($B$2:B2) gives a running average.
Common errors
- Forgetting the dollar signs.
=SUM(B2:B2)filled down becomes=SUM(B3:B3), so each row shows only its own value, not a total. - Locking both ends.
=SUM($B$2:$B$2)gives the same number in every row. - Locking the wrong end.
=SUM(B$2:B2)works for rows, but=SUM($B2:B$2)does not grow downward, because the row of the end is locked. - Inserting a row above the start. If you insert a row above row 2, the anchor
$B$2moves to$B$3and the new row is not in the total. Insert rows inside the data, or include a header row in the range, to avoid this. - Sorting the data. A running total depends on row order. If you sort the data, the formulas still sum from the top, so the totals reflect the new order.
Practice
Exercise
Column B holds daily expenses in B2:B31. Write a formula for C2 that gives a running total and can be filled down to C31. What does C10 contain after filling?
Show answer
C2 is =SUM($B$2:B2). After filling down, C10 contains =SUM($B$2:B10), the total of the expenses from B2 through B10.
Exercise
A colleague wrote =SUM(B$2:B2) in C2 and filled it down. Is the result a correct running total? Why or why not?
Show answer
Yes. The row of the start is locked (B$2), so it stays on row 2 when filled down. The end B2 is relative and moves, so the range grows. It only fails if you fill it across, because the column is not locked.