Syntax
| Parameter | Description |
|---|---|
| initial_value | Parameter of the SCAN function. |
| array | Parameter of the SCAN function. |
| lambda | Parameter of the SCAN function. |
Examples
Running total (cumulative sum)
=SCAN(0, A1:A10, LAMBDA(acc, val, acc+val))
Cumulative product
=SCAN(1, B1:B5, LAMBDA(acc, val, acc*val))
Running maximum
=SCAN(-9E+307, C1:C20, LAMBDA(mx, val, MAX(mx, val)))
Common Errors
The LAMBDA doesn't accept exactly 2 parameters (accumulator and current value).
The LAMBDA produces an error during one of the iterations.
Tips
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.
=SCAN(startingBalance, transactions, LAMBDA(bal, txn, bal+txn)) creates a running balance column from a list of deposits and withdrawals.
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