DATASET
Generates a table row by row, where each row is computed from the previous one. DATASET takes a row count followed by one or more column definitions, each with a starting value and a lambda that calculates the next value โ useful for building sequences, running totals, and iterative calculations without writing each row by hand.
Syntax
DATASET(
rowCount,
currentName1, initialValue1, nextName1, lambda1,
currentName2, initialValue2, nextName2, lambda2,
...
)rowCount (Number): Number of rows to generate. Must be at least 0.
currentName (String): Name under which the value from the previous row is available.
initialValue: The starting value used for the first row.
nextName (String): Name under which the newly computed value becomes available to later columns in the same row.
lambda (Function): Function that computes the next value.
Returns: Table โ a table with one row per generated step. Returns an empty table when rowCount is 0.
Requires at least 5 arguments: the row count plus one complete column block of four arguments. Each additional column adds another block of four.
How it works
The first row contains the initialValue of each column. For every following row, the previous row's values are exposed through the currentName names, and each column's lambda computes the new value. Columns are evaluated left to right, so a later column can read a newly computed value from an earlier column in the same row through its nextName.
Names like "x" and "x2" are strings and must be quoted. Lambda parameters are identifiers and are not quoted.
Examples
Build a simple sequence
DATASET(3, "x", 1, "x2", function(x: x + 1))Returns the table [[1], [2], [3]].
Two dependent columns
DATASET(
3,
"x", 1, "x2", function(x, y: x + 1),
"y", 10, "y2", function(x, y, x2: x2 * 10)
)Returns the table [[1, 10], [2, 20], [3, 30]]. The second column reads the first column's newly computed value x2 from the same row.
Running total
Accumulate a running total across rows by adding each row's previous value:
DATASET(4, "total", 0, "total2", function(total: total + 100))Returns [[0], [100], [200], [300]].
Common mistakes
Unquoted names โ
currentNameandnextNamemust be strings ("x"). Unquotedxis treated as a variable reference.Wrong argument count โ each column needs exactly four arguments (currentName, initialValue, nextName, lambda).
Fractional row count โ
rowCountis rounded down withMath.floor. A value like 3.9 generates 3 rows, and 0.9 generates 0 rows.Lambda errors โ if a lambda fails while building a row,
DATASETpasses the error through and does not add the incomplete row.
DATASET runs in the browser, but the server-side evaluation returns an error because it cannot execute lambdas. Formulas that rely on DATASET may therefore fail in server-side contexts.
Error messages
Error | Cause |
|---|---|
| Missing the row count or a full column block |
| Row count is not a number |
| Row count is negative |
| Arguments after the row count are not grouped in blocks of four |
|
|
|
|
| A lambda argument is not a function |
See Also
MAP ยท ARRAY ยท TABLEFILTER ยท Advanced FormulaScript