SCAN Function

Like REDUCE, but shows the running result at every step — perfect for running totals.

Category

Logical

Available in

Microsoft 365, Excel 2024

Returns

A spilled array of every intermediate result

Taught hands-on in Level 5: Expert Techniques & Workbook Architecture - Modern Functions module

Overview

SCAN works exactly like REDUCE, except it spills every intermediate value instead of only the last one.

That makes it the cleanest way to build running totals, running balances and running maximums with one formula.

Syntax

=SCAN([initial_value], array, lambda(accumulator, value))

Arguments

ArgumentRequired?What it does
initial_valueOptionalWhere the accumulator starts.
arrayYesThe values to work through.
lambdaYesA LAMBDA with two parameters — the accumulator and the current value — that returns the new accumulator.

Examples

Example 1 — Running total

Show year-to-date sales beside each month.

C2fx=SCAN(0, B2:B5, LAMBDA(a, v, a+v))
ABC
1MonthSalesTo date
2Jan400400
3Feb350750
4Mar5001250
5Apr2751525
=SCAN(0, B2:B5, LAMBDA(a, v, a+v)) Explain

Example 2 — Running best

The highest monthly sales figure so far.

=SCAN(0, B2:B13, LAMBDA(best, v, MAX(best, v))) Explain

Example 3 — Running balance

Apply each month's growth rate and show the balance after every month.

=SCAN(1000, B2:B5, LAMBDA(bal, r, bal*(1+r))) Explain

With rates of 5%, 3%, -2% and 4% this spills 1,050, 1,081.50, 1,059.87 and 1,102.26.

Common mistakes

  • Text in the array. Adding text gives #VALUE!. Clean the column or wrap the value in N().

Notes

Kyle Stott

Author

Kyle Stott

Certified Microsoft Excel Expert

Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.