SCAN function in Google Sheets
Scans an array and produces intermediate values by application of a LAMBDA function to each value. Returns an array of the intermediate values obtained at each step.
=SCAN(initial_value, array_or_range, LAMBDA)SCAN syntax and parameters
Three arguments, three required.
- initial_valueanyRequired
The initial accumulator value.
- array_or_rangeanyRequired
An array or range to be scanned.
- LAMBDAanyRequired
A LAMBDA that’s applied to each value in array_or_range for scanning it. Syntax: LAMBDA(name1, name2, formula_expression) Requirements: The LAMBDA must have exactly 2 name arguments along with a formula_expression which uses those names. The name1 resolves to the current value in the accumulator and name2 resolves to the current_value in array_or_range, when applying the LAMBDA. The accumulator is updated in each step to the intermediate value obtained in the previous step.
SCAN examples
Formulas you'll actually reuse.
A running total down the column — every intermediate value:
=SCAN(0, D2:D200, LAMBDA(acc, x, acc + x))The record-to-date — the biggest deal seen so far on each row:
=SCAN(0, D2:D200, LAMBDA(acc, x, MAX(acc, x)))
SCAN in Excel
Same name — your formula ports as-is.
Try SCAN in the playground
Edit the example — nothing to install.
Preloaded with the SCAN formula from Example 1 — change anything and watch it respond.
Related functions
More ways Google Sheets gets this done.
- BYCOLGroups an array by columns by application of a LAMBDA function to each column.ArrayExcel
- BYROWGroups an array by rows by application of a LAMBDA function to each row.ArrayExcel
- CHOOSECOLSCreates a new array from the selected columns in the existing range.ArrayExcel
- CHOOSEROWSCreates a new array from the selected rows in the existing range.ArrayExcel
- HSTACKAppends ranges horizontally and in sequence to return a larger array.ArrayExcel
- LINESTGiven partial data about a linear trend, calculates various parameters about the ideal linear trend using the least-squares method.ArrayExcel