Sheet Clinic

MAP, REDUCE and SCAN in Google Sheets: running total, test each row

When ARRAYFORMULA with SUM or AND gives one cell, SCAN builds a running total, MAP checks each row and REDUCE keeps the final value.

Sheet Clinic editorsPublished
E2=SCAN(0, C2:C9, LAMBDA(total, x, total + x))

Before SUM and AND inside ARRAYFORMULA

ABCDEF
1DateSellerAmountRunning totalRow OK
2Nov 3Emily42225FALSE
3Nov 3Jacob35
4Nov 418
5Nov 4Olivia0
6Nov 5Michael27
7Nov 5Sarah50
8Nov 6David31
9Nov 6Emily22

What changed

  1. E2 SUM to SCAN
  2. F2 AND to MAP

After SCAN in E2, MAP in F2

ABCDEF
1DateSellerAmountRunning totalRow OK
2Nov 3Emily4242TRUE
3Nov 3Jacob3577TRUE
4Nov 41895FALSE
5Nov 4Olivia095FALSE
6Nov 5Michael27122TRUE
7Nov 5Sarah50172TRUE
8Nov 6David31203TRUE
9Nov 6Emily22225TRUE
Figure 1. Same eight entries. On the left each formula collapses to one cell; on the right each one fills E2:E9 or F2:F9.

Type one formula at the top of the column and let it fill the rows under it. For a running total that formula is =SCAN(0, C2:C9, LAMBDA(total, x, total + x)) in E2, and for a TRUE or FALSE on each row it is =MAP(B2:B9, C2:C9, LAMBDA(name, amt, AND(name<>"", amt>0))) in F2. In the take-home copy each one filled eight cells. REDUCE takes the same three arguments as SCAN and hands back only the final step: =REDUCE(0, C2:C9, LAMBDA(total, x, total + x)) returned 225, the last number in the SCAN column. On your own sheet, put your amount range where C2:C9 is, and in MAP list the columns your test reads, with one LAMBDA name for each.

You reach for these three when a formula ought to give one answer per row and gives one answer for the whole range instead. The Broken tab shows exactly that. A small cash log sits in A2:C9 with a date, a seller and an amount on each row. E2 holds =ARRAYFORMULA(SUM(C2:C9)) and F2 holds =ARRAYFORMULA(AND(B2:B9<>"", C2:C9>0)). E2 came back 225, F2 came back FALSE, and E3:F9 stayed empty.

ARRAYFORMULA does not split SUM or AND into rows. Both functions read a whole range and return one value, with or without the wrapper. The lone FALSE says some row failed the test and gives no hint which one.

Broken tab with F2 selected. The formula bar shows =ARRAYFORMULA(AND(B2:B9<>"", C2:C9>0)). E2 shows 225, F2 shows FALSE, and E3:F9 are empty.
Figure 2. The Broken tab. One value in E2, one in F2, nothing under them.

SCAN keeps every step of a running total, REDUCE keeps the last

SCAN wants a starting value, the range, and a LAMBDA with two names. In the Fixed tab the names are total and x. Sheets starts total at 0, adds the amount in C2, writes 42 in E2, and carries that 42 into the next row. Google's SCAN page calls the first name the accumulator and says it is updated at each step, which is what column E shows: 42, 77, 95, 95, 122, 172, 203, 225. The 95 appears twice because Olivia's amount in C5 is 0.

The names are yours to pick. The first one always holds the running value and the second holds the current cell, whatever you call them, and the page above says a LAMBDA with any other number of names returns #N/A.

Fixed tab with E2 selected. The formula bar shows =SCAN(0, C2:C9, LAMBDA(total, x, total + x)). E2:E9 read 42, 77, 95, 95, 122, 172, 203, 225. F2:F9 read TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE. H2 shows 225.
Figure 3. The Fixed tab. Column E is the SCAN result, column F the MAP result, and H2 is REDUCE.

H2 on the same tab has the REDUCE version. It returned 225, matching both E9 and the SUM on the Broken tab. For a plain total that makes REDUCE a longer way to write SUM. The extra typing pays off when each step needs a rule SUM can't express, and the REDUCE page has one that adds a price only when it reaches a set amount. Since the two functions take identical arguments, you can build the formula as SCAN first, check every intermediate value in its column, and then change the name to REDUCE to keep just the end result.

Input8 amounts in C2:C9
Formula=SCAN(0, C2:C9, LAMBDA(total, x, total + x))
Expected42, 77, 95, 95, 122, 172, 203, 225
Sheets returned42, 77, 95, 95, 122, 172, 203, 225 Matches expected
Checked2026-11-11, free personal account

MAP for a test on each row, and open ranges that run past the data

MAP takes one or more ranges and a LAMBDA with one name per range. In F2, B2:B9 feeds name and C2:C9 feeds amt, so on row 4 the LAMBDA sees an empty name and 18. The AND inside it only ever sees one row at a time, which is why it can return a separate answer for each. F4 and F5 came back FALSE. Row 4 has no seller, and row 5 has Olivia with an amount of 0. The other six rows are TRUE. Google's MAP page adds that each value has to map to a single result; a LAMBDA that returns a whole array for one row is not supported.

Columns E and F on the Try it yourself tab still hold the formulas from the Broken tab. Replace E2 with the SCAN formula and F2 with the MAP formula from the top of this page, and E2:F9 should match the Fixed tab cell for cell.

The Whole column tab tries the same formulas on open ranges, the kind people use so new rows are picked up automatically. =SCAN(0, C2:C, LAMBDA(total, x, total + x)) in E2 kept going past the data. E10, E11 and every row below repeat 225, all the way to the last row of the sheet. =MAP(B2:B, C2:C, LAMBDA(name, amt, AND(name<>"", amt>0))) in G2 runs past the data too, and every empty row below it is FALSE, because an empty seller fails the test. F2 keeps the open range and hides the extra rows by wrapping the SCAN in an IF on column C: =ARRAYFORMULA(IF(C2:C="", "", SCAN(0, C2:C, LAMBDA(total, x, total + x)))). F2:F9 match E2:E9, and F10 down are blank. The same IF wrapper on a formula that needs no LAMBDA is in the post on ARRAYFORMULA down a whole column.

Whole column tab with F2 selected. The formula bar shows =ARRAYFORMULA(IF(C2:C="", "", SCAN(0, C2:C, LAMBDA(total, x, total + x)))). Column E repeats 225 from row 10 down, column F is blank from row 10, and column G shows FALSE from row 10 down.
Figure 4. Open ranges. Column E keeps repeating 225 below the data, while F stops at row 9.

The IF wrapper on the Whole column tab blanks a row whenever its amount cell is empty. An amount left empty in the middle of the log would get an empty cell in column F as well, so a row with no money needs a 0 typed in C, the way Olivia's row has one.

Take-home copy. Four tabs: Broken, Fixed, Try it yourself, Whole column. It opens as a copy in your own Drive.

Copy the sheet