Array

SCAN Formula

Applies a LAMBDA function sequentially to each element of an array while keeping an accumulator, but unlike REDUCE, it returns all intermediate accumulated values as an array. SCAN is perfect for running totals, cumulative products, or any calculation where you need to see the accumulation at every step.

Syntax

SCAN(initial_value, array, lambda)
ParameterDescription
initial_value Parameter of the SCAN function.
array Parameter of the SCAN function.
lambda Parameter of the SCAN function.
Try SCAN in Viztab — free, no signup

Examples

Running total (cumulative sum)

Formula
=SCAN(0, A1:A10, LAMBDA(acc, val, acc+val))
Returns 10 values showing the running total at each row. If A1:A3 is 100, 200, 300, results are 100, 300, 600.

Cumulative product

Formula
=SCAN(1, B1:B5, LAMBDA(acc, val, acc*val))
Returns the cumulative product at each step. For values 2, 3, 4: results are 2, 6, 24.

Running maximum

Formula
=SCAN(-9E+307, C1:C20, LAMBDA(mx, val, MAX(mx, val)))
Tracks the maximum value seen so far at each row. The running max never decreases — it shows the highest value encountered up to each point.

Common Errors

#VALUE!

The LAMBDA doesn't accept exactly 2 parameters (accumulator and current value).

#CALC!

The LAMBDA produces an error during one of the iterations.

Tips

SCAN vs REDUCE

REDUCE gives you one final value; SCAN gives you an array showing every intermediate value along the way. Use SCAN when you need the full trail, not just the end result.

Running balance in bank statement

=SCAN(startingBalance, transactions, LAMBDA(bal, txn, bal+txn)) creates a running balance column from a list of deposits and withdrawals.

Choose initial value carefully

For running sums, start with 0. For running products, start with 1. For running max, start with a very small number or the first element itself.

Try SCAN in Viztab

Import your data and use SCAN with 370+ other formulas. No signup required.

Open Viztab

Related Formulas