Scripting
Lido provides formulas for running JavaScript code, creating reusable lambda functions, and mapping functions over data. These are non-action formulas — they execute immediately during formula evaluation.
EVALJS
Evaluates a JavaScript expression and returns the result. The code runs in a sandboxed QuickJS environment with a 5-minute timeout.
Syntax:
=EVALJS(code)
Parameters:
| Parameter | Description | Required |
|---|---|---|
code | JavaScript code to evaluate | Yes |
Allowed return types: number, string, boolean. For other types, return them as a JSON string.
Examples:
=EVALJS("2 + 2")
→ 4
=EVALJS("'hello'.toUpperCase()")
→ "HELLO"
=EVALJS("JSON.stringify({a: 1, b: [2, 3]})")
→ '{"a":1,"b":[2,3]}'
Tips
- EVALJS runs in an isolated sandbox — it cannot access the DOM, network, or spreadsheet data directly
- To pass spreadsheet data into EVALJS, concatenate it into the code string:
=EVALJS("'" & A1 & "'.split(',').length") - For complex logic, combine EVALJS with LAMBDA and MAP to process table data row by row
LAMBDA
Creates a reusable function that can be passed to MAP or stored in a named cell for use as a custom formula.
Syntax:
=LAMBDA(arg1, arg2, ..., formula)
Parameters:
| Parameter | Description | Required |
|---|---|---|
arg1, arg2, ... | Parameter names for the function | Yes (at least one) |
formula | The formula body that uses the parameters | Yes (last argument) |
The last argument is always the formula body; all preceding arguments are parameter names.
Example:
=LAMBDA(x, y, x * y + 1)
Creates a function that takes two arguments and returns x * y + 1.
Named Cell Lambdas
LAMBDA becomes especially powerful when combined with named cells. If you name a cell (by editing the cell name input to the left of the formula bar) and that cell contains a LAMBDA formula, the cell name becomes a callable formula anywhere in your spreadsheet.
Example:
- In cell A1, enter:
=LAMBDA(x, x * 2 + 1) - Name the cell
DOUBLE_PLUS_ONE(via the name box) - Now use it anywhere:
=DOUBLE_PLUS_ONE(5)→11
This pattern is especially useful with EVALJS for creating reusable JavaScript macros:
- Name a cell
PARSE_CSV - Enter:
=LAMBDA(text, EVALJS("'" & text & "'.split(',').length")) - Use it:
=PARSE_CSV("a,b,c")→3
MAP
Applies a function (LAMBDA) to each row of one or more columns/ranges and returns the results as a column.
Syntax:
=MAP(values, function)
=MAP(values1, values2, ..., function)
Parameters:
| Parameter | Description | Required |
|---|---|---|
values1, values2, ... | Column ranges or table column references to iterate over | Yes (at least one) |
function | A LAMBDA function or reference to a named cell containing a LAMBDA | Yes (last argument) |
All value columns must have the same number of rows. The function receives one value per column for each row.
Examples:
Single column:
=MAP(A1:A10, LAMBDA(x, x * 2))
Doubles each value in A1:A10.
Multiple columns:
=MAP(Orders[@Price], Orders[@Quantity], LAMBDA(price, qty, price * qty))
Multiplies Price by Quantity for each row in the Orders table.
With a named cell lambda:
=MAP(A1:A10, MY_CUSTOM_FUNCTION)
Where MY_CUSTOM_FUNCTION is a named cell containing a LAMBDA formula.
Tips
- MAP works with cell ranges (
A1:A10), table column references (Orders[@Price]), or evaluated arrays - When using multiple value arguments, they must all have the same number of rows
- The function argument must be a LAMBDA (inline or referenced by name)