MAKEARRAY Function in Google Sheets – LAMBDA Helper Function

The MAKEARRAY function in Google Sheets generates an array of a specified size, with each value calculated by a custom lambda function.

The Lamba function has access to the row and column indices for each value.

Let’s see a simple example:

=MAKEARRAY(5,3,LAMBDA(row, col, row + col))

This generates an array with 5 rows and 3 columns.

The value of each element in the row is the sum of the row position and the column position, within the array.

So the first value is 2 (row 1 + column 1) and the final value is 8 (row 5 + column 3). The indices are in relation to the position within the array, not the position within the Google Sheet.

Makearray Function Simple Example

đź”— Get this example and others in the template at the bottom of this article.

Continue reading MAKEARRAY Function in Google Sheets – LAMBDA Helper Function

SCAN Function in Google Sheets – LAMBDA Helper Function

The SCAN function in Google Sheets scans an array and applies a LAMBDA function to each value, moving row by row. The output is an array of intermediate values obtained at each step.

It’s hard to understand without seeing an example, so let’s do that.

The most straightforward SCAN formula is to create a running total calculation on a column of numbers.

The formula is:

=SCAN(0,A2:A11,LAMBDA(runningTotal,currentValue,runningTotal + currentValue))

Which produces this array output:

Scan Function Running Total Calculation

The lambda simply adds together the current running total and the new value, then returns the answer to the output array.

When all of the values from the input array have been considered, the output array is returned.

đź”— Get this example and others in the template at the bottom of this article.

Continue reading SCAN Function in Google Sheets – LAMBDA Helper Function

REDUCE Function in Google Sheets – LAMBDA Helper Function

The REDUCE function in Google Sheets turns an array input into a single value, by applying a custom LAMBDA function to each value of the input array.

It reduces an array down to a single value.

It’s best to understand through a simple example:

Cumulative Reduce Function Google Sheets

The formula in this example is:

=REDUCE(0,A2:A6,LAMBDA(total,x,total+x))

The REDUCE function takes a starting value (0 in this example), an input array, and then a custom LAMBDA function.

The formula applies the custom LAMBDA function to each value in the array. In this case, it takes the current total value and adds the next value in the array to it to make a new total. This new total is passed on to the next iteration.

So this REDUCE formula calculates the cumulative total of the 5 numbers.

(And yes, this formula also gets you there:

=SUM(A2:A6)

This REDUCE was deliberately simple to show you how it works.)

đź”— Get this example and others in the template at the bottom of this article.

Continue reading REDUCE Function in Google Sheets – LAMBDA Helper Function