[]
        
(Showing Draft Content)

LAMBDA

This function allows you to create and name custom reusable functions that can be called like any other function.

Syntax

=LAMBDA([parameter1, parameter2, …,], calculation)

Arguments

This function has these arguments:

Argument

Description

parameter

[Optional] A value that you want to pass to the function, such as a cell reference, string or number. You can enter up to 253 parameters.

calculation

[Required] The formula you want to execute and return as the result of the function. It must be the last argument and it must return a result.

Remarks

  • If an incorrect number of parameters or more than 253 parameters are provided to a LAMBDA function, it returns a #VALUE! error.

  • If an incorrect number of arguments is passed to a LAMBDA function, it returns a #VALUE! error.

  • If you call a LAMBDA function from within itself and the call is circular, it returns a #NUM! error.

  • If you create a LAMBDA function in a cell without also calling it from within the cell, it returns a #CALC! error.

Note: If the lambda function is recursive, the maximum recursion depth is related to the browser.

Data Types

The concise format returns a text value, whereas the strict format returns an array of the same size and shape as the input.

Examples

The following code sample shows the basic usage of LAMBDA function.

//basic usage of LAMBDA function using one parameter
sheet.setValue(1, 1, "Converted Temp");
spread.addCustomName('ToCelsius', 'LAMBDA(temp, (5/9) * (temp-32))');
sheet.setFormula(2, 1, 'ToCelsius(104)'); // result is 40
            
//basic usage of LAMBDA function using two parameters
sheet.setValue(1, 3, "Calculated Hypotenuse");
spread.addCustomName('Hypotenuse', 'LAMBDA(a, b, SQRT((a^2+b^2)))');
sheet.setFormula(2, 3, 'Hypotenuse(3, 4)'); // result is 5

The below output will be generated:

image.png

Lambda Helper Functions

SpreadJS supports seven new LAMBDA helper functions. These functions help creating re-usable LAMBDA functions by having LAMBDA function as a parameter. They also serve as stand-alone functions themselves. For more information, refer:

  1. BYROW

  2. BYCOL

  3. ISOMITTED

  4. MAKEARRAY

  5. MAP

  6. REDUCE

  7. SCAN