ID EN
#Dynamic array

SCAN

Excel Functions

Scan array and return intermediate results

Syntax

EXCEL
=SCAN([initial_value], array, function)

Arguments

Parameter Description
initial_value [optional] The initial value of the accumulator. Default is zero.
array The array to be scanned.
function The function or custom LAMBDA to apply.

Return Value

An array of results

Details

The SCAN function applies a custom calculation to each element in a given array and returns an array that contains each intermediate value created during the scan. SCAN can generate running totals, running counts, and other calculations that create intermediate or incremental results. The results returned by SCAN are the value of an "accumulator" at each step in the process. Like the REDUCE function, SCAN iterates over all elements in an array and performs a calculation on each element while updating the value of an accumulator. However, while REDUCE returns a single value, SCAN returns an array of values. The SCAN function takes three arguments: initial_value, array, and function. Initial_value is the initial seed value to use for the first result. Initial_value is optional and defaults t

Examples

LAMBDA structure

The SCAN function takes three arguments: initial_value, array, and function. Initial_value is the initial seed value to use for the first result. Init

EXCEL
LAMBDA(a,v,calculation)
LAMBDA structure

The first argument, a, is the accumulator used to store intermediate values. The accumulator begins as the initial_value provided to SCAN and changes

EXCEL
=SCAN(0,{1,2,3},LAMBDA(a,v,a+v)) // returns {1,3,6}
SCAN for a basic running total

A simple use of SCAN is to create a running total. In the worksheet shown below, we have a list of values in the range B5:B16, and we want to create a

EXCEL
=SCAN(0,B5:B16,LAMBDA(a,v,a+v))
SCAN with abbreviated function syntax

Like other newer dynamic array functions, SCAN supports an abbreviated syntax for the function argument. Using the abbreviated syntax, the formula abo

EXCEL
=SCAN(0,B5:B16,SUM)
SCAN with abbreviated function syntax

It is not obvious, but SCAN is delivering two values, the accumulator and the value to the SUM function at each loop. The result is a running total. W

EXCEL
=SCAN(0,B5:B16,COUNT) // returns {2,2,2,2,2,2,2,2,2,2,2,2}
SCAN with a dynamic range

One of SCAN's key strengths is its ability to work with dynamic arrays. When you give SCAN an array that is dynamically generated, it will automatical

EXCEL
=SCAN(0,TRIMRANGE(B5:B1000,2),SUM)

See Also

LAMBDA LET MAP SCAN REDUCE MAKEARRAY BYCOL BYROW