How-to recipes · Counting and summing

How to calculate a running total in Excel

Build a cumulative sum that grows row by row with SUM and a mixed reference, SCAN in Microsoft 365, or a running total per group with SUMIF.

Beginner SUM SCAN LAMBDA SUMIF INDEX

A running total, also called a cumulative sum, shows how a figure builds up over time: sales year-to-date after each month, the balance of an account after each transaction, the number of units produced so far this week. Each row shows the sum of everything from the first row down to the current one. It is easy to build, but there are a few traps, especially when rows are inserted, sorted, or when the data lives in an Excel table.

The example data

Monthly sales for the first half of the year in A1:B7. The running total in column C should end with the half-year total in C7.

Every version: SUM with an expanding range

In C2 type the formula below and copy it down to C7:

C4fx=SUM($B$2:B4)
ABC
1MonthSalesRunning
2Jan4200
3Feb3900
4Mar460012700
5Apr5100
6May3800
7Jun4700

This is the formula as it appears in C4 after copying: January to March, 4200 + 3900 + 4600.

Result: 12700

The trick is the mixed reference $B$2:B2 in the first row. The start $B$2 is locked with dollar signs, so it never moves. The end B2 is relative, so when you copy the formula one row down it becomes B3, then B4, and the range grows by one row each time. Cell references: relative, absolute and mixed explains absolute and relative references in detail.

The "previous plus current" version

Another common formula is =B2 in C2 and =C2+B3 in C3, copied down. It is slightly faster on huge sheets because each row adds just two numbers. The drawback: if you delete a row, every formula below it shows #REF!, and if C1 holds a header, writing =C1+B2 in C2 gives #VALUE!. The SUM version is more robust.

Microsoft 365: one formula with SCAN

SCAN walks through an array and keeps an accumulator, returning every intermediate value. With LAMBDA it produces the whole running total from one cell:

C2fx=SCAN(0,B2:B7,LAMBDA(total,x,total+x))
ABC
1MonthSales
2Jan42004200
3Feb39008100
4Mar460012700
5Apr510017800
6May380021600
7Jun470026300

SCAN starts at 0, adds each month's sales, and spills all six intermediate totals.

total is the running value and x is the current cell. Because it is a single formula, you cannot accidentally overwrite or forget to copy one row. When B2:B7 is a table column or grows, point SCAN at the whole column of the table.

A running total per group

When the list contains several people or products mixed together, you usually want each one's own running total. Use SUMIF with two expanding ranges:

C5fx=SUMIF($A$2:A5,A5,$B$2:B5)
ABC
1RepSalesRep total
2Ana300
3Ben250
4Ana150
5Ben400650
6Ana200

In row 5, Ben's sales so far are 250 + 400. Copy the formula from C2 down to C6.

Result: 650

Each row adds only the earlier rows that have the same rep. The data does not need to be sorted, but if it is sorted by date, the result reads as each person's year-to-date figure.

Running totals inside an Excel table

Tables use structured references, and =SUM([@Sales]) refers only to the current row. To get an expanding range in a table, use INDEX to build the start of the range: =SUM(INDEX([Sales],1):[@Sales]). INDEX returns a reference to the first cell of the column, and the colon creates a range from there to the current row. Unlike $B$2:B2, this survives sorting and adding rows.

Pitfalls

  • Sorting. Running totals depend on row order. Sort by date before reading them, and remember that re-sorting by another column produces meaningless cumulative numbers.
  • Inserting rows at the top. Inserting a row above row 2 changes $B$2 into $B$3 in the existing formulas, and the new row is not included. Insert new data inside the range or use a table.
  • Filtering. SUM includes hidden rows. For a running total of only the visible rows, use =SUBTOTAL(109,$B$2:B2); see How to sum only visible cells in Excel.
  • Text in the Sales column. A value like n/a is ignored by SUM but breaks the C2+B3 version with #VALUE!.
Tip. A running total is a natural partner for a line chart that shows progress towards a target. To express each month as a share of the total instead, see How to calculate percentage of total in Excel.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

More how-to recipes