# How to calculate a running total with ARRAYFORMULA in Google Sheets

Sum every row up to the current one with SUMIF on row numbers: `=ARRAYFORMULA(IF(B2:B12="","",SUMIF(ROW(B2:B12),"<="&ROW(B2:B12),B2:B12)))`.

**Google Sheets:** `=ARRAYFORMULA(IF(B2:B12="","",SUMIF(ROW(B2:B12),"<="&ROW(B2:B12),B2:B12)))`

**Excel:** In Excel, fill `=SUM($B$2:B2)` down, or in Microsoft 365 use `=SCAN(0,B2:B9,LAMBDA(a,x,a+x))`.

## Example

Sample data (row 1 is the header):

| A | B | C |
| --- | --- | --- |
| Date | Amount | Running total |
| 2026-03-02 | 1250 |  |
| 2026-03-03 | 430 |  |
| 2026-03-05 | 875 |  |
| 2026-03-09 | 2100 |  |
| 2026-03-10 | 315 |  |
| 2026-03-12 | 960 |  |
| 2026-03-16 | 1480 |  |
| 2026-03-18 | 690 |  |

Formula in C2: `=ARRAYFORMULA(IF(B2:B12="","",SUMIF(ROW(B2:B12),"<="&ROW(B2:B12),B2:B12)))`

Result (spills 11 × 1): $1,250; $1,680; $2,555; $4,655; $4,970; $5,930; $7,410; $8,100; ; ; 

## How it works

For each row, SUMIF adds up the amounts whose row number is less than or equal to that row's number: row 2 sums one amount, row 3 sums two, and so on. ARRAYFORMULA runs that once per row, and the IF keeps the spare rows at the bottom blank until an amount is entered.

## Other ways

- `=ARRAYFORMULA(SUMIF(ROW(B2:B12),"<="&ROW(B2:B12),B2:B12))`: Without the blank test, the final total repeats down the empty rows. (8,100 repeated in rows 10 to 12.)

## Common mistakes

- The total follows the row order, not the dates. Sort the data by date first, or the running total jumps around.
- On thousands of rows this recalculates slowly, since every row sums all the rows above it. Newer Sheets has SCAN: `=SCAN(0,B2:B12,LAMBDA(total,x,total+x))`.
- Point it at an open range like `B2:B` to cover future rows, but keep the IF, or every empty row to the bottom of the sheet shows the final total.

## Questions

**How do I restart the total for each category?**

Sum only the rows above with the same category, filled down from C2: `=SUMIFS($B$2:B2,$A$2:A2,A2)`.

**Can I do it with a simple fill-down formula?**

Yes: `=SUM($B$2:B2)` in C2, filled down. ARRAYFORMULA saves you from refilling when rows are added.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/running-total-with-arrayformula
