# Fontana Formula language

This document is the complete definition of the Fontana formula language: the body of a Formula operation, which any data node can host, and the conditional formatting of a view (View formulas). Every function listed here exists; a function that is not listed does not exist. Every example under Worked examples is a golden test that runs exactly as shown.

## What a formula is

A formula is the body of a Formula operation. Every data node hosts a list of operations, and Formula is the recommended one wherever an operation is picked: it carries lineage and data styles, which a Query or a Script cannot. Its expressions are Notion Formula 2.0, so `prop("Name").upper()` works as in Notion. The formula itself returns rows: it is an ordered list of **statements**, and each statement runs on the current row array and passes the resulting array to the next statement. The first statement reads the rows arriving at that operation — the stage before it, or the node's single wire. The last statement is what the operation writes onward. Statements can set fields, drop rows, insert, split and append rows, sort, group, aggregate, and raise exceptions.

```text
input rows
  → statement 1 → rows₁
  → statement 2 → rows₂
  → … → rows written by the operation
```

Statements run top to bottom. Row order inside one statement is the array order arriving at that statement, and `rowIndex()` is the current row's position in it. A formula cannot run arbitrary JavaScript, read other rows of its own input outside `groupBy`, `rowIndex()` and `context()`, or call the network. When several wires feed the node, each is a named table the formula reads with `inputs()`; nothing merges on its own.

A `.ffl` file may declare **named exports** as markdown fences: a line with three backticks then `ffl name`, the statements for that export, then a closing line of three backticks. The name is the info-string; do not write `ffl name` labels. `$ref` `file.ffl#name` extracts the fence body. `ffl()` in expression position is an ordinary call. A file is either unfenced (the whole file is the default export) or named (every export is a fence) — never mixed.

A **view formula** is the other kind: the conditional formatting of a table, board, list, calendar, timeline or details view. It uses the same expressions, runs on one row at a time, and styles what the view shows instead of returning rows; see View formulas.

Normalise, drop, raise, group, aggregate:

```text
if(
  prop("Created by").equal("buy"),
  setProp("Created by", "BUY"),
  setProp("Created by", "SELL")
)

filter(prop("expired") != 1)

if(
  prop("owner").empty(),
  raiseException()
    .setProp("message", "Owner is missing")
    .setProp("severityLevel", 3)
)

groupBy(prop("owner"), prop("ISIN"))

setProp("owner", prop("owner").first())
setProp("ISIN", prop("ISIN").first())
setProp("price", prop("price").sum())
```

Highest price, using context:

```text
context().setProp("highestPrice", 0)

if(
  prop("price") > context().prop("highestPrice"),
  context().setProp("highestPrice", prop("price"))
)

setProp("isHighest", prop("price") == context().prop("highestPrice"))
```

### Writing statements

- A statement ends at a newline where parentheses and brackets are balanced and the next non-blank line does not start with `.`. A line that starts with `.` continues the previous statement, which is how `raiseException()` and `insertRow()` chain `.setProp(…)` across lines, and how a formula chains `.setStyle(…)`, `.setRowStyle(…)`, `.clearStyle(…)` and `.clearRowStyle(…)`.
- Blank lines are ignored. Comments are Notion comments, `/* ... */`, and `#` to the end of the line; a comment-only line is a blank line and a trailing `# …` does not keep a statement open. Strings use double quotes, with `\"` and `\\` as escapes. Backtick text (`` `…` ``) is raw: it spans lines, keeps every character as written, and has no escapes, for a query, a template or a prompt; it cannot contain a backtick. Comments, newlines, and indentation do not change expression values.
- Call names are case-sensitive (`setProp`, `groupBy`, `dropRow`).
- A bare expression in statement position (`prop("price") + 1`) is a type error. Values are written with `setProp`.
- The name arguments of `setProp`, `unsetProp`, `keepProps`, `splitRows`, `context().setProp` and a chained `.setProp` are text literals. `spreadProps().prefix(text)` takes a text literal too.
- `prop("Exact schema name")` reads a field by its exact schema name. An unknown field is a type error (`Cannot find property "Name"`). The editor knows the input schema plus every field an earlier Formula operation set, on the same stack or on an operation node upstream. After a Script or Query operation, which can add columns the editor cannot see, a field the editor does not know is typed `any` and a known field keeps its type. `getProp(name)` is the same function as `prop(name)`.

## Statements

| Statement | Resulting rows |
| --- | --- |
| `setProp(name, expression)` | Every row, with that field set to the expression. A new name adds a field. |
| `unsetProp(name)` | Every row, with that field removed. |
| `keepProps(name, …)` | Every row, with only those fields, in that order. Every other field is removed. `keepProps("owner")` returns rows that hold nothing but `owner`; a name the row does not have is a type error. |
| `dropRow()` | The current row is absent from the output. A bare `dropRow()` drops every row. |
| `insertRow()` followed by any number of `.setProp(name, value)` | The current row, then a copy of it as it stands at that point. The chained `.setProp` calls set fields on the copy; their expressions read the current row; every other cell is copied. Allowed inside `if()` and `do()`. Later statements see the inserted rows; the inserting statement never runs over them. Replacing a row is `do(insertRow().setProp(…), insertRow().setProp(…), dropRow())`: the inserts stay, the original goes. |
| `splitRows(list, name)` | One row per item of `list`, the item written under `name`, every other field copied. An item that is an object is carried whole, so `.prop` reads its fields afterwards: this is how the rows inside an envelope (`{ date, name, rows: [...] }`) become rows. An empty list drops the row. A row-set statement like `groupBy`: a type error inside `if()` or `do()`. |
| `appendRows(table)` | The current rows, then every row of a named table, each with the data styles that table carries. The row type afterwards is the merge of both sides, so a column only one side has reads `empty` on the other. An appended row has no input row behind it: a `raiseException` on one files the ticket under the output row. A row-set statement like `groupBy`: a type error inside `if()`, `do()` or `each()`. |
| `spreadProps(object)` followed by optional `.prefix(text)` and `.value(expression)` in either order | Every row, with one level of the object's fields written as columns, named by their keys, after the row's existing columns. `.prefix("p.")` joins that text onto each name. `.value(expression)` is evaluated per field with `current` bound to that field's value; without it the cell is the field's value. A plain `prop("x")` argument removes that column after the spread. Empty adds nothing. A collision with an existing column, a non-object value, or an empty or reserved name fails the run. A row-set statement like `groupBy`: a type error inside `if()`, `do()` or `each()`. |
| `each(list, statement)`, or `list.each(statement)` | Every row, with the statement run once per item of `list` on that same row: `current` is the item and `index` its zero-based position. An empty list or an empty value runs it zero times; a value that is not a list fails the run. The body sets and unsets row fields, raises, writes context, branches with `if()` and `do()`, and nests another `each()`. `current` is read-only and the list is not written back, so `dropRow()`, `filter()`, `keepProps()` and the row-set statements are a type error inside it. A `raiseException` there needs both a field and a key. |
| `if(condition, statement)` | The branch runs where the condition is true. Other rows pass through. |
| `if(condition, statement, statement)` | One branch per row. |
| `do(statement, …)` | Those statements run left to right on the same row. This is how one branch sets two fields or raises and then drops. |
| `filter(condition)` | Rows where the condition is true. `filter(prop("expired") != 1)` is the same row set as `if(prop("expired").equal(1), dropRow())`. |
| `sortBy(expression, …)` | All rows, stable-sorted. The first key is primary. A key is ascending unless wrapped in `desc(...)`. `sortBy(prop("owner"), desc(prop("price")))` sorts by owner ascending, then price descending. Empties sort last in both directions. |
| `desc(expression)` | Valid only as a `sortBy` argument: that key sorts descending. |
| `groupBy(expression, …)` | One row per key tuple. One argument per key field. Every field becomes the list of member values, plus `__groupKey` and `__groupIndices` (shape under groupBy and aggregation). |
| `raiseException()`, `raiseException(field)`, `raiseException(field, key)`, each followed by any number of `.setProp(name, value)` | Every row is still emitted. The current row also records an exception. The chained `.setProp` calls set exception fields (`message`, `severityLevel` or `severity`, `type`, and any other Exception Management field such as `status` or assignee), not data columns. |
| `context().setProp(name, expression)` | Rows pass through. The context value changes. |
| `context().prop(name)` | An expression, not a statement: the context value `name`. |
| `inputs().prop(handle)` | An expression, not a statement: the named table whose input port handle is `handle`. |
| `rowIndex()` | An expression, not a statement: the current row's zero-based position in the rows entering the statement. |

An inserted or split row's provenance is the row it was copied from: lineage and exception tickets follow it onto every copy. An appended row's provenance is the table row it came from, on the wire that table arrived on.

`if` inside an expression is still Notion: `setProp("Side", if(prop("Side") == "buy", "BUY", "SELL"))`. `if` whose branch is `setProp`, `dropRow`, `raiseException`, `do`, or a context write is a statement. Both branches of one `if` are statements, or both are values.

`each` is the one statement that runs a statement several times on one row, once per item of a list. It is how a check runs per item of a nested list — one exception per item, on the row that holds the list — without `splitRows` first flattening the rows. A field only some items set exists on every row afterwards, `empty` where no item set it, which is the rule an `if` without an else branch follows. One step of the run's budget is charged per item, as a list callback charges per element.

`rowIndex()` is the current row's zero-based position in the array entering the statement, so `setProp("n", rowIndex() + 1)` numbers the rows in arrival order and `inputs().prop("b").rows().at(rowIndex())` merges two wires position by position (past the end of the shorter table the read is `empty`). Inside a list callback and inside an `each` body, `index` is still the item's position and `rowIndex()` is still the row's. After a `filter`, `sortBy` or `groupBy` the position is the one that statement produced, not the node's input order, and the editor warns about it.

The one-argument `filter(condition)` is the row statement. The two-argument `filter(list, condition)` and the dot form `list.filter(condition)` are the Notion list function. Arity decides. A one-argument `filter` whose argument is not a boolean is a type error. `filter(condition)` keeps the rows where the condition is true, as `filter([1, 2, 3], current > 1)` is `[2, 3]`; `if(condition, dropRow())` drops where the condition is true.

## Types

Values are `text`, `number`, `boolean`, `date`, `list<T>`, `object` (a JSON object inside a cell) and `empty` (an absent value). The named tables add `table<handle>` (one wire's rows) and `row<handle>` (one row of it). A field whose schema type is unknown is `any`. Input fields take their type from the JSON schema: `string` is `text` (`date` when the format is `date` or `date-time`), `number` and `integer` are `number`, `boolean` is `boolean`, `array` is `list` of its item type, `object` is an `object` of the properties it names, each typed the same way.

**Row type threads through statements.** The type checker starts from the input schema and carries a row type from statement to statement, so `prop("price")` is a number before `groupBy` and a list of numbers after it, and a number again after `setProp("price", prop("price").sum())`. A field has one type at any point, as in Notion. `setProp` on an existing field with a value of a different type is a type error. A field that only one `if` branch sets exists on every row after the `if` (the other rows hold `empty`) and has that branch's type; two branches that set the same field to different types are a type error. A field set on an inserted row (`insertRow().setProp(name, value)`) follows the same `setProp` rules, reading the current row's type; a field that only inserted rows set exists afterwards on every row with that type, `empty` on the rows that were not inserted. `splitRows(list, name)` gives `name` the item type of `list` under the `setProp` rules, so `splitRows(prop("tags"), "tag")` on `tags: list<text>` makes `tag` a `text`. `spreadProps(object)` types each spread column from a known object schema, or opens the row when the object is open or `any`. Inside `each(list, statement)`, `current` is the item type of `list` and `index` is a number; the row type after the `each` merges the body's row with the one entering it under the same one-side rule. `appendRows(table)` merges the table's columns with the row entering it the same way. `unsetProp` removes the field from the row type; `keepProps` keeps only the named fields, in that order. After `groupBy`, every field `T` is `list<T>`, `__groupKey` is `list<any>` and `__groupIndices` is `list<number>`.

**Reserved column names.** A column named `__proto__`, `constructor`, `toString`, `valueOf`, `hasOwnProperty`, `isPrototypeOf`, `propertyIsEnumerable`, `toLocaleString` or `__defineGetter__` and friends — any own member name of `Object.prototype` — cannot be written: `setProp`, `insertRow().setProp`, the `splitRows` name and a `spreadProps` column (after the prefix) report `Column name "constructor" is reserved`. Reading such a column is legal, so a formula can still carry one a load boundary rejected.

Numbers are written to cells as JavaScript numbers by the field's schema kind (`integer` truncates); a numeric field `setProp` creates is `float`. Dates are written as ISO-8601 UTC strings. A field no statement wrote keeps its input cell exactly as it arrived. After an `if`, `do`, `each` or `insertRow`, a field one branch (or one item of an `each`, or only the inserted rows) set holds `empty` on the other rows.

### groupBy and aggregation

`groupBy` takes one expression per key field. Rows match when every key value is equal under Notion `==` (no concatenation, so `"ab"` + `"c"` and `"a"` + `"bc"` stay different groups). Group rows appear in first-seen order. Members stay in input order.

```text
groupBy(prop("owner"), prop("ISIN"))
```

emits rows shaped like:

```text
{
  __groupKey: ["zoltan", "SOMEISIN"],
  __groupIndices: [0, 1],
  owner: ["zoltan", "zoltan"],
  ISIN: ["SOMEISIN", "SOMEISIN"],
  price: [3, 6]
}
```

`__groupKey` is always a list of the key values, including when there is one key field. Every input field becomes a list of member values, including the key fields. `__groupIndices` is the zero-based indices of those members in the statement input.

Later statements in the same formula can read those two helpers. A later `groupBy` replaces them with that group's own helpers and does not listify the previous ones. The rows the operation writes onward omit `__groupKey` and `__groupIndices`. To keep a key for the next node, copy it first: `setProp("groupKey", prop("__groupKey"))`.

The next statement sees those lists, so Notion list reducers are the aggregation step:

```text
setProp("owner", prop("owner").first())
setProp("ISIN", prop("ISIN").first())
setProp("price", prop("price").sum())
```

`sum`, `first`, `last`, `min`, `max`, `mean`, `median`, `count`, and `unique` are the Notion functions. `sum(prop("price"))` on a row that still has a scalar price is a type error. Cross-row totals without `groupBy` are a context scan.

### Context

One context object lives for the whole formula execution. It starts empty. A `context().setProp` during a row is visible to later rows in that statement and to every later statement. A constant write such as `context().setProp("highestPrice", 0)` runs once per row and leaves that constant. Reads are `context().prop(name)`.

Context is formula state; it is not returned to the next node. `inputs()` and `context()` are the two environment objects; both read with `.prop`, and only `context()` has `.setProp`.

A context key's type is the type of its first `context().setProp` in source order. Reading a key before any statement writes it is a type error, so the highest-price example must open with `context().setProp("highestPrice", 0)`.

### Named tables and inputs()

Every wire into the node is a **named table**: its name is the input port's handle, and `inputs()` is the set of them. That is how a node with several wires merges them — nothing merges on its own, a formula does it — and how one wire enriches another: a column is matched, and a column is taken.

```text
setProp("ibor_value", inputs().prop("ibor_valuations").find("ISIN", prop("ISIN")).prop("value"))
```

- `inputs().prop(handle)` is the named table whose input port handle is `handle`. An unknown handle is a type error (`Cannot find input "x"`). The first wire into a node has the handle `input`, so `inputs().prop("input")` is that wire; `input()` is the node's own row set, which is the same rows at the first operation and the previous operation's output after that.
- `table.find(column, value)` is the first table row, in table order, whose `column` equals `value` under Notion `==`; `empty` when none matches. `table.findAll(column, value)` is the list of every matching row in table order. `table.rows()` is every row.
- `table.exceptions()` is for a node's trigger condition only: the exceptions raised in the current build anywhere upstream of the table's wire (the node wired in and every node before it, each raising node counted once), counted by severity and read with `.prop("info")` (levels 1 and 2), `.prop("warning")` (level 3) and `.prop("error")` (levels 4 and 5). On `input()` the counts cover everything upstream of the node, through every wire. In a Formula operation it fails with `exceptions() is only available in a node condition`.
- `row.prop(name)` reads a table row's field, typed from that table's schema. `row.props()` is not in v1.
- A table's columns come from the wire's upstream schema and from its loaded rows. When neither names any column, the table is open: `find`, `findAll` and `row.prop` accept any column name, typed `any`; a column the table turns out not to have matches nothing and reads `empty` when the formula runs. A column the schema or the rows do name keeps its type, and a table with known columns still reports an unknown one.
- A miss leaves the value `empty`; `setProp` of `empty` writes an empty cell. Write the miss explicitly when a different value is wanted: `let(hit, inputs().prop("ibor_valuations").find("ISIN", prop("ISIN")), if(empty(hit), -1, hit.prop("value")))`.
- A table carries the data styles of the port it came in on, so a value taken out of one keeps the marks of the cell it came from, and `appendRows(table)` keeps each appended row's styles.
- `appendRows(table)` is how a formula unions two wires; `at(rowIndex())` is how it merges them by position.

A named table is read-only: no statement writes to a table, and a table is not a row-array value, so `sortBy` and `groupBy` do not apply to it.

### Objects inside a cell

A cell whose schema type is `object` is an `object` value, and `.prop` reads its fields the way it reads a table row's:

```text
each(prop("legs"), if(empty(current.prop("ISIN")), raiseException("legs", concat(prop("tradeId"), ":", format(index)))))
```

- A property the schema names keeps its type, and a name it does not name is a type error, as on a named table with known columns. An object whose schema names no properties is open: every name is allowed, typed `any`, and a field the value turns out not to have reads `empty`. A cell under an `any` field is read that way too, so a nested JSON object is reachable even where no schema describes it.
- A property whose type is `object` is itself an object, so `current.prop("issuer").prop("country")` reads the nested field. `.prop` on text, a number, a boolean or a date fails the run: those have no fields.
- A list of objects is `list<object>`, so the list functions read them: `prop("legs").filter(current.prop("side") == "BUY")` is the buy legs, and `prop("legs").map(current.prop("notional")).sum()` is their total notional.
- `splitRows` over a list of objects carries each object under its name, typed as the schema types the list's items: `splitRows(prop("rows"), "item")` then `setProp("isin", prop("item").prop("isin"))` turns the list into rows and its fields into columns, one `setProp` per field. A list of lists of objects (a table's grid of cells) splits the same way, each row carrying its list.
- `spreadProps(object)` writes one level of an object's fields as columns. On `{"id": "p1", "price": {"value": 101.2, "ccy": "EUR"}}`, `spreadProps(prop("price"))` adds `value` and `ccy` and removes `price`. A field that is itself an object becomes a column holding that object; a second `spreadProps` on that column, with a prefix, goes one level deeper. `.value(expression)` unwraps each field: `spreadProps(prop("properties")).value(ifs(current.prop("type") == "number", current.prop("number"), current))`.
- An object is not storable. `setProp` of an object, or of a list of objects, is a type error: a cell holds text, a number, a boolean, a date, or a list of those. A cell no statement writes keeps its input JSON exactly as it arrived, so reading an object never rewrites it, and an object a statement only carried — the list `groupBy` built from its members, the item `splitRows` wrote, a copy of a field whose type the schema does not name — is written back as the JSON it came from.

### Exceptions

`raiseException()` records an Exception Management row for the current data row and leaves that data row in the output. Dropping is a separate `dropRow()` in the same `do(...)` when both are wanted.

`raiseException` takes up to two arguments that pin the ticket:

| Form | Column | Identity |
| --- | --- | --- |
| `raiseException()` | none | content hash of the raising row |
| `raiseException(field)` | `field` | content hash of the raising row |
| `raiseException(field, key)` | `field` | `key` |

`field` is a text literal naming a field on the current row type. `key` is any text or number expression, for example `concat(prop("owner"), prop("ISIN"))`; another type is a type error. The same key on a later run updates the ticket when the row changed, and a key that a later run no longer raises inactivates the ticket. That is how a corrected document resolves an exception it raised earlier. Tickets persist independently of run data, so dropping the row in the same `do(...)` does not remove them.

Inside `each`, only `raiseException(field, key)` is valid: the other two forms are a type error there. The identity of an unkeyed raise is the content hash of the raising row, which is the same for every item of that row's list, so the items' tickets would collapse into one. The key is the whole identity of the ticket across the node, so it has to tell the row apart as well as the item: `concat(prop("tradeId"), ":", format(index))` gives every item of every row its own ticket, where `format(index)` alone would give one ticket to the first item of every row. An item a later run no longer raises inactivates its ticket alone.

Chained `setProp` on the exception sets exception fields, not data columns:

- `message` — exception message
- `severityLevel` — integer 1 through 5. `severity` is the same property.
- `type` — exception type label
- any other Exception Management field (`status`, `assignee` / `assigneeUserId`, `deleted`, or a custom property), by property id or name. The value is stored when the exception is first created. A name that is not a field on this workflow still raises the ticket and records a field error.

A literal severity outside 1–5 is an editor error. A runtime value outside 1–5 still raises the exception, omits `severityLevel`, and records a formula error on that field.

Raising an exception never stops a node. At any severity the raising node keeps every row, ends with its normal status, and the exception is not counted among its errors; only a runtime failure fails a node. The node's output port counts its exceptions by severity: `info` for levels 1 and 2, `warning` for level 3, `error` for levels 4 and 5. The nodes wired to that output run as usual and read every row. A node is held back for upstream exceptions only by its own trigger condition, which reads the counts of every node upstream of it, not only the node wired directly in, with `exceptions()`:`input().exceptions().prop("warning") == 0 and input().exceptions().prop("error") == 0` is the condition new Save File and Email Export nodes start with. The level is stored on the ticket when it is first created, so raising the same ticket later with another level changes the port's counts in that build and leaves the ticket's severity as it is.

## View formulas

A view formula is the conditional formatting of a db-explorer view: a table, board, list, calendar, timeline or details view. It runs on every row the view shows, one row at a time, top to bottom, and never changes data. It styles the row and its fields, and it can change the text a field shows.

```text
if(test(prop("Fund ID"), "14$"), setStyle("Fund ID", "background", "lime"))

if(
  prop("Reporting GP").contains("Partners"),
  setStyle("Reporting GP", "icon", "thumbsup")
    .setStyle("Reporting GP", "text_color", "indigo")
)

if(prop("NAV") < prop("Commitment"), setStyle("Fund name", "text_color", "rose"))

setStyle("Status", "dot", optionColor("Status"))

if(prop("Assignee").includes(me()), setRowStyle("background", "sky"))
```

| Statement | Effect |
| --- | --- |
| `setStyle(field, key, value)` | Sets one style key on one field of the row. |
| `setRowStyle(key, value)` | Sets one style key on the row itself. |
| `clearStyle(field)`, `clearStyle(field, key)` | Removes every style key from one field of the row, or just that key. |
| `clearRowStyle()`, `clearRowStyle(key)` | Removes every style key from the row itself, or just that key. |
| `setProp(name, value)` | Changes the text the view shows for an existing field. |
| `if(condition, statement)`, `if(condition, statement, statement)` | As in an operation. |
| `do(statement, …)` | As in an operation. |

- `let`, `lets` and every expression function work as in an operation. Every other statement (`unsetProp`, `keepProps`, `dropRow`, `filter`, `sortBy`, `groupBy`, `splitRows`, `appendRows`, `spreadProps`, `raiseException`, `insertRow`, `context().setProp`) and the operation environment (`context()`, `inputs()`, `input()`, `rowIndex()`, `findAll`, `rows`, `exceptions`, `desc`) are type errors in a view formula. `me()` and `optionColor()` are type errors in an operation formula: a run cannot know who is looking, and option colours belong to the view. The style statements are not — an operation writes **data styles**, which ride on its output and follow value lineage. Every style key works in both modes, `icon` included: a host that validates a style resolves icon references.
- Fields are named as the view shows them: `prop("Name")`, the field argument of `setStyle` and the name of `setProp`. A field the view does not have is a type error; renaming a field does not rewrite the formula. Select and status fields read as the option name (`text`), multi-select and people fields as a `list<text>` of names, date fields as `date`, checkbox fields as `boolean`, number fields as `number`, every other field as `text`.
- Field names and style keys are text literals. Style calls chain in any mix: `setStyle("A", "bold", true).setStyle("B", "dot", "rose").setRowStyle("background", "sky")`.
- Statements run top to bottom. When two writes set the same key on the same target for one row, the later write wins. A value that is empty writes nothing, so `setStyle("Status", "background", optionColor("Status"))` paints only rows whose option has a colour.
- Row and field styles are separate layers. The row layer paints the element that shows the row: the whole row in a table, the card on a board, the item in a list, the chip on a calendar, the row label beside the bar on a timeline, the record in a details view. A field background sits above the row background, and a row icon or dot appears once for the row. The row's text styles (`text_color`, `bold`, `italic`, `underline`, `strikethrough`, `size`) reach every field that does not set that key itself.
- `setProp(name, value)` is display only: the view shows the value as `format()` renders it, whatever the field's type, while sort, filter, search, grouping, header tiles, editing and export keep the stored value. Later statements read the new value: after `setProp("Amount", "N/A")` the field reads as `text`, and when only one `if` branch changes its type it reads as `any`.
- `me()` is the signed-in viewer's name, or empty where the view has no signed-in viewer: `prop("Assignee").includes(me())`.
- `optionColor(field)` is the colour token of the option the row holds in a select, status or multi-select field (the first selected option that has a colour), or empty when it has none.
- There are no `startsWith` or `endsWith` functions: write `test(prop("Fund ID"), "^14")` and `test(prop("Fund ID"), "14$")`.
- A runtime error fails only its row: that row gets no styles and no display text, every other row still paints, and the editor lists the failing rows with their messages. Expressions keep their operation semantics, so a blank numeric operand is an error; guard it: `if(not(empty(prop("NAV"))) and not(empty(prop("Commitment"))) and prop("NAV") < prop("Commitment"), …)`. The step limit applies to each row.
- A formula with a type error paints nothing until it checks clean.

Style keys, one value each. A colour token is a name from the colour chooser, such as `lime`, `indigo`, `rose` or `gray`; a literal that is not one is a type error that lists them. A computed value that is not a valid colour, size or icon fails its row.

| Key | Value |
| --- | --- |
| `background` | colour token: background |
| `background_strong` | colour token: a stronger background |
| `text_color` | colour token: text colour |
| `border_top` | colour token: top border |
| `border_right` | colour token: right border |
| `border_bottom` | colour token: bottom border |
| `border_left` | colour token: left border |
| `dot` | colour token: a colour dot before the value |
| `icon_color` | colour token: the icon's colour (otherwise the text colour) |
| `bold` | boolean: bold text |
| `italic` | boolean: italic text |
| `underline` | boolean: underlined text |
| `strikethrough` | boolean: struck-through text |
| `size` | `"large"` or `"small"`: text size |
| `icon` | icon reference: an icon before the value, by its name in the asset library (`"thumbsup"`) or a Heroicons reference (`"heroicons:outline/star"`) |

## Expressions

Inside any expression position the language is Notion Formula 2.0, with the limits below.

- Calls: `upper(name)` and `name.upper()` are the same. The receiver is the first argument.
- Lists: `[1, 2, 3]`.
- `let(name, value, body)` and `lets(name, value, …, body)` bind names for the body.
- List callbacks (`map`, `filter`, `find`, `findIndex`, `some`, `every`) bind `current` and `index` (zero-based) only inside the callback: `[1, 2, 3].map(current * 2)`.
- Operators, tightest first: calls and dots; unary `not` / `!` / `-`; `^` (right-associative, `2 ^ 2 ^ 3` = `256`); `*` `/` `%`; `+` `-`; `==` `!=` `!==` `>` `>=` `<` `<=`; `and` / `&&`; `or` / `||`; ternary `? :`. `!=` and `!==` match. Ternary `X ? Y : Z` matches `if(X, Y, Z)`. `and(a, b)`, `or(a, b)` and `not(a)` are also calls.
- `+` is number-plus-number or text-plus-text. `"1" == 1` is false. `empty(0)`, `empty("")`, and `empty([])` are true.
- There is one blank text value: an empty text cell and `""` are equal (`prop("owner") == ""` is true for both), fall in one `groupBy` group and match each other in `find`, `includes` and `unique`.
- `<`, `<=`, `>`, `>=` order numbers, text, dates, or booleans (`false < true`); `sortBy` keys are the same kinds.
- `[1, 2] == [2, 1]` is false.
- Every number is an exact decimal: literals, `prop` reads, arithmetic, and list reducers. `5 / 10` is `0.5`.
- A number literal may group its digits with `_`: `130_000_000` is `130000000`. A separator sits between two digits only.
- Dates are UTC, written as ISO-8601 strings. `now()` and `today()` read one fixed clock per run. Date units: `"years"`, `"quarters"`, `"months"`, `"weeks"`, `"days"`, `"hours"`, `"minutes"`. `formatDate` takes Moment tokens (`YYYY`, `MMMM`, `MMM`, `MM`, `DD`, `Do`, `D`, `dddd`, `HH`, `hh`, `h`, `mm`, `ss`, `A`, `a`, …, listed under `formatDate`), text in `[brackets]` is written as is, and any other letter is an error.
- `test`, `match`, `replace`, and `replaceAll` take JavaScript regular expressions as text (`"\\d+"`).
- A call that is not listed under Functions is an unknown function (`Cannot find function len()`). That includes `link`, `style`, `unstyle`, `name`, `email`, and `id`.
- A cell is read the first time a statement uses it: a column the formula never reads is passed through as it arrived, and only a cell the formula reads can fail the run.
- Parentheses, brackets and the expression tree nest at most 100 levels deep.

A runtime failure fails the whole formula operation and writes no rows (in a view formula, only its row): division by zero ("Division by zero"), an invalid regex, a blank numeric operand ("Numeric operand is empty"; a blank number is not `0`), a non-numeric text in a numeric position ("Cannot parse numeric operand"), a date cell that is not ISO-8601 ("Cannot parse date cell"), a boolean cell that is not `true` / `false` ("Cannot parse boolean cell"), or a limit exceeded. The limits:

| Limit | Value |
| --- | --- |
| Evaluation steps per expression on one row, per row in a view formula (list functions charge one step per element) | 2000000 |
| Regex pattern length | 512 |
| Regex subject length | 100000 |
| `repeat` count | 10000 |
| List length | 100000 |
| Text length produced by `concat` / `join` / `repeat` / `replace` / `replaceAll`, and by one `map` in total | 1000000 |

## Grammar

W3C-style EBNF generated from the parser. Quoted strings are literal tokens; `identifier`, `text`, `number` and `newline` are the pattern tokens defined at the end.

```ebnf
(* Fontana Formula grammar. Generated from FormulaParser; do not edit. *)
(* newline ends a statement only where ( ) and [ ] are balanced and the next non-blank line does not start with "."; every other newline is whitespace. *)
(* Whitespace /[ \t\r]+/ and comments (/* ... */, or # to the end of the line) may appear between any two tokens. *)
(* In unary, "not" directly followed by "(" is the call not(...) of primary. *)
(* ffl at statement start followed by an identifier with no "(" is a label; ffl() is a call. *)

program        ::= ( statement ( newline statement )* )?
statement      ::= label | expression
label          ::= "ffl" identifier
expression     ::= orExpression ( "?" expression ":" expression )?
orExpression   ::= andExpression ( ( "or" | "||" ) andExpression )*
andExpression  ::= comparison ( ( "and" | "&&" ) comparison )*
comparison     ::= additive ( ( "==" | "!=" | "!==" | ">" | ">=" | "<" | "<=" ) additive )*
additive       ::= multiplicative ( ( "+" | "-" ) multiplicative )*
multiplicative ::= power ( ( "*" | "/" | "%" ) power )*
power          ::= unary ( "^" power )?
unary          ::= "not" unary | "!" unary | "-" unary | postfix
postfix        ::= primary dotCall*
dotCall        ::= "." functionName argumentList
functionName   ::= identifier | "and" | "or" | "not" | "ffl"
argumentList   ::= "(" ( expression ( "," expression )* )? ")"
primary        ::= text | rawText | number | "true" | "false" | list | "(" expression ")" | identifier argumentList? | ( "and" | "or" | "not" | "ffl" ) argumentList
list           ::= "[" ( expression ( "," expression )* )? "]"

(* Tokens *)
newline    ::= /\n/
identifier ::= /[A-Za-z_][A-Za-z0-9_]*/
text       ::= /"([^"\\\n]|\\[^\n])*"/
rawText    ::= /`[^`]*`/
number     ::= /[0-9](_?[0-9])*(\.[0-9](_?[0-9])*)?([eE][+-]?[0-9](_?[0-9])*)?/
```

## Functions

Every function of the language, by family. Signatures list the receiver first; a name documented in several families (`filter`, `find`, `if`, `setProp`, `prop`) is one function whose argument count and receiver pick the form. A form whose description says *Fontana extension* works here but is not Notion 2.0 (`concat(text, …)`, the third argument of `formatNumber`); write the Notion form when the formula should also hold in Notion.

### Logic

#### `if`

Returns the first value if the condition is true; otherwise, returns the second value.

```text
if(condition: boolean, then: any, else: any) → any
```

- `if(true, 1, 2)` gives `1`
- `if(false, 1, 2)` gives `2`
- `true ? "Complete" : "Incomplete"` gives `"Complete"`

#### `ifs`

Returns the value of the first true condition, or the last value when none is true, in place of nested if() calls.

```text
ifs(condition: boolean, value: any, condition2: boolean, value2: any, …, else: any) → any
```

- `ifs(true, 1, true, 2, 3)` gives `1`
- `ifs(false, 1, true, 2, 3)` gives `2`
- `ifs(false, 1, false, 2, 3)` gives `3`

#### `empty`

Returns true if the value is empty; 0, "", and [] are empty.

```text
empty(value: any) → boolean
```

Also callable as `receiver.empty(…)`, with the receiver as the first argument.

- `empty(0)` gives `true`
- `empty("")` gives `true`
- `empty([])` gives `true`
- `"Notion".empty()` gives `false`

#### `equal`

Returns true if both values are equal and false otherwise, the same as ==.

```text
equal(a: any, b: any) → boolean
```

Also callable as `receiver.equal(…)`, with the receiver as the first argument.

- `equal(1, 1)` gives `true`
- `"a" == "b"` gives `false`
- `"1" == 1` gives `false`
- `[1, 2] == [2, 1]` gives `false`

#### `unequal`

Returns false if both values are equal and true otherwise, the same as !=.

```text
unequal(a: any, b: any) → boolean
```

Also callable as `receiver.unequal(…)`, with the receiver as the first argument.

- `unequal(1, 2)` gives `true`
- `"a" != "a"` gives `false`

#### `and`

Returns the logical AND of its two arguments.

```text
and(a: boolean, b: boolean) → boolean
```

Also callable as `receiver.and(…)`, with the receiver as the first argument.

- `and(true, false)` gives `false`
- `true && true` gives `true`
- `true and false` gives `false`

#### `or`

Returns the logical OR of its two arguments.

```text
or(a: boolean, b: boolean) → boolean
```

Also callable as `receiver.or(…)`, with the receiver as the first argument.

- `or(true, false)` gives `true`
- `false || false` gives `false`
- `false or true` gives `true`

#### `not`

Returns the logical NOT of its argument.

```text
not(value: boolean) → boolean
```

Also callable as `receiver.not(…)`, with the receiver as the first argument.

- `not(true)` gives `false`
- `!false` gives `true`
- `not true` gives `false`

#### `let`

Binds a name to a value for the body expression, so a value computed once can be used several times.

```text
let(name, value: any, body: any) → any
```

- `let(x, 10, x * 2)` gives `20`
- `let(word, "go", word + word)` gives `"gogo"`

#### `lets`

Binds several names in order for the body expression; each value can use the names bound before it.

```text
lets(name, value: any, name2, value2: any, …, body: any) → any
```

- `lets(a, 1, b, a + 1, a + b)` gives `3`

### Text

#### `length`

Returns the length of the text or list value.

```text
length(text: text) → number
length(list: list<any>) → number
```

Also callable as `receiver.length(…)`, with the receiver as the first argument.

- `length("hello")` gives `5`
- `"Notion".length()` gives `6`
- `length([1, 2, 3])` gives `3`

#### `substring`

Returns the part of the text from the start index (inclusive) to the optional end index (exclusive).

```text
substring(text: text, start: number, end?: number) → text
```

Also callable as `receiver.substring(…)`, with the receiver as the first argument.

- `substring("Notion", 0, 3)` gives `"Not"`
- `substring("Notion", 3)` gives `"ion"`

#### `contains`

Returns true if the search text is present in the value.

```text
contains(text: text, search: text) → boolean
```

Also callable as `receiver.contains(…)`, with the receiver as the first argument.

- `contains("Notion", "ot")` gives `true`
- `"Notion".contains("x")` gives `false`

#### `test`

Returns true if the value matches the regular expression and false otherwise.

```text
test(text: text, pattern: text) → boolean
```

Also callable as `receiver.test(…)`, with the receiver as the first argument.

- `test("Notion", "Not")` gives `true`
- `test("Notion", "\\d")` gives `false`

#### `match`

Returns every match of the regular expression as a list.

```text
match(text: text, pattern: text) → list<text>
```

Also callable as `receiver.match(…)`, with the receiver as the first argument.

- `match("Notion Notion", "Not")` gives `["Not", "Not"]`
- `match("Notion 123 Notion 456", "\\d+")` gives `["123", "456"]`

#### `replace`

Replaces the first match of the regular expression with the replacement text.

```text
replace(text: text, pattern: text, replacement: text) → text
```

Also callable as `receiver.replace(…)`, with the receiver as the first argument.

- `replace("Notion Notion", "N", "M")` gives `"Motion Notion"`

#### `replaceAll`

Replaces every match of the regular expression with the replacement text.

```text
replaceAll(text: text, pattern: text, replacement: text) → text
```

Also callable as `receiver.replaceAll(…)`, with the receiver as the first argument.

- `replaceAll("Notion Notion", "N", "M")` gives `"Motion Motion"`
- `"Notion 123".replaceAll("\\d", "")` gives `"Notion "`

#### `lower`

Converts the text to lowercase.

```text
lower(text: text) → text
```

Also callable as `receiver.lower(…)`, with the receiver as the first argument.

- `lower("NOTION")` gives `"notion"`
- `"NOTION".lower()` gives `"notion"`

#### `upper`

Converts the text to uppercase.

```text
upper(text: text) → text
```

Also callable as `receiver.upper(…)`, with the receiver as the first argument.

- `upper("notion")` gives `"NOTION"`
- `"notion".upper()` gives `"NOTION"`

#### `repeat`

Repeats the text the given number of times.

```text
repeat(text: text, times: number) → text
```

Also callable as `receiver.repeat(…)`, with the receiver as the first argument.

- `repeat("0", 4)` gives `"0000"`
- `"~=".repeat(10)` gives `"~=~=~=~=~=~=~=~=~=~="`

#### `trim`

Removes whitespace from the beginning and end of the text.

```text
trim(text: text) → text
```

Also callable as `receiver.trim(…)`, with the receiver as the first argument.

- `trim("  Notion  ")` gives `"Notion"`
- `" Notion ".trim()` gives `"Notion"`

#### `format`

Converts any value to text; the text conversion for a function or operator that needs text. Numbers print without grouping, dates as ISO-8601 UTC.

```text
format(value: any) → text
```

Also callable as `receiver.format(…)`, with the receiver as the first argument.

- `format(prop("qty"))` gives `"3"`
- `format(1234)` gives `"1234"`
- `format(1234567.5)` gives `"1234567.5"`
- `format(true)` gives `"true"`

#### `padStart`

Pads the beginning of the value, formatted as text, with the pad text until it reaches the given length.

```text
padStart(value: text, length: number, pad: text) → text
padStart(value: text, length: number, pad: number) → text
padStart(value: number, length: number, pad: text) → text
padStart(value: number, length: number, pad: number) → text
```

Also callable as `receiver.padStart(…)`, with the receiver as the first argument.

- `"A".padStart(3, ".")` gives `"..A"`
- `123.padStart(5, 0)` gives `"00123"`
- `"hi".padStart(5, "!")` gives `"!!!hi"`
- `"hi".padStart(5, "!".length())` gives `"111hi"`

#### `padEnd`

Pads the end of the value, formatted as text, with the pad text until it reaches the given length.

```text
padEnd(value: text, length: number, pad: text) → text
padEnd(value: text, length: number, pad: number) → text
padEnd(value: number, length: number, pad: text) → text
padEnd(value: number, length: number, pad: number) → text
```

Also callable as `receiver.padEnd(…)`, with the receiver as the first argument.

- `"A".padEnd(3, ".")` gives `"A.."`
- `123.padEnd(5, 0)` gives `"12300"`

#### `isValidIsin`

Returns true if the text is a valid ISIN: twelve characters, a two-letter country prefix, and a correct check digit. Empty text is false.

```text
isValidIsin(text: text) → boolean
```

Also callable as `receiver.isValidIsin(…)`, with the receiver as the first argument.

- `isValidIsin("US0378331005")` gives `true`
- `"US0378331006".isValidIsin()` gives `false`

### Numbers

#### `add`

Returns the sum of two numbers.

```text
add(a: number, b: number) → number
```

Also callable as `receiver.add(…)`, with the receiver as the first argument.

- `add(5, 10)` gives `15`
- `5 + 10` gives `15`

#### `subtract`

Returns the difference of two numbers.

```text
subtract(a: number, b: number) → number
```

Also callable as `receiver.subtract(…)`, with the receiver as the first argument.

- `subtract(5, 10)` gives `-5`
- `5 - 10` gives `-5`

#### `multiply`

Returns the product of two numbers.

```text
multiply(a: number, b: number) → number
```

Also callable as `receiver.multiply(…)`, with the receiver as the first argument.

- `multiply(5, 10)` gives `50`
- `5 * 10` gives `50`

#### `divide`

Returns the quotient of two numbers.

```text
divide(a: number, b: number) → number
```

Also callable as `receiver.divide(…)`, with the receiver as the first argument.

- `divide(5, 10)` gives `0.5`
- `5 / 10` gives `0.5`

#### `mod`

Returns the first number modulo the second number; the result has the sign of the first.

```text
mod(a: number, b: number) → number
```

Also callable as `receiver.mod(…)`, with the receiver as the first argument.

- `mod(5, 10)` gives `5`
- `5 % 10` gives `5`

#### `pow`

Returns the result of a base number raised to an exponent power.

```text
pow(a: number, b: number) → number
```

Also callable as `receiver.pow(…)`, with the receiver as the first argument.

- `pow(5, 10)` gives `9765625`
- `5 ^ 10` gives `9765625`

#### `min`

Returns the smallest number of the arguments.

```text
min(a: number, b: number, …more: number) → number
min(list: list<number>, …more: number) → number
```

Also callable as `receiver.min(…)`, with the receiver as the first argument.

- `min(1, 2, 3)` gives `1`
- `min([1, 2, 3])` gives `1`

#### `max`

Returns the largest number of the arguments.

```text
max(a: number, b: number, …more: number) → number
max(list: list<number>, …more: number) → number
```

Also callable as `receiver.max(…)`, with the receiver as the first argument.

- `max(1, 2, 3)` gives `3`
- `max([1, 2, 3])` gives `3`

#### `sum`

Returns the sum of its arguments.

```text
sum(a: number, b: number, …more: number) → number
sum(list: list<number>, …more: number) → number
```

Also callable as `receiver.sum(…)`, with the receiver as the first argument.

- `sum(1, 2, 3)` gives `6`
- `sum([1, 2, 3], 4, 5)` gives `15`

#### `median`

Returns the middle value of its arguments.

```text
median(a: number, b: number, …more: number) → number
median(list: list<number>, …more: number) → number
```

Also callable as `receiver.median(…)`, with the receiver as the first argument.

- `median(1, 2, 4)` gives `2`
- `median([1, 2, 3], 4)` gives `2.5`

#### `mean`

Returns the arithmetic average of its arguments.

```text
mean(a: number, b: number, …more: number) → number
mean(list: list<number>, …more: number) → number
```

Also callable as `receiver.mean(…)`, with the receiver as the first argument.

- `mean(1, 2, 3)` gives `2`
- `mean([1, 2, 3], 4, 5)` gives `3`

#### `abs`

Returns the absolute value of the number.

```text
abs(number: number) → number
```

Also callable as `receiver.abs(…)`, with the receiver as the first argument.

- `abs(10)` gives `10`
- `abs(-10)` gives `10`

#### `round`

Returns the number rounded to the nearest integer, or to the given decimal places; halves round away from zero.

```text
round(number: number, places?: number) → number
```

Also callable as `receiver.round(…)`, with the receiver as the first argument.

- `round(0.4)` gives `0`
- `round(-0.6)` gives `-1`
- `round(1.234, 0)` gives `1`
- `round(1.234, 2)` gives `1.23`
- `round(1234, -2)` gives `1200`

#### `ceil`

Returns the smallest integer greater than or equal to the number.

```text
ceil(number: number) → number
```

Also callable as `receiver.ceil(…)`, with the receiver as the first argument.

- `ceil(0.4)` gives `1`
- `ceil(-0.6)` gives `0`

#### `floor`

Returns the largest integer less than or equal to the number.

```text
floor(number: number) → number
```

Also callable as `receiver.floor(…)`, with the receiver as the first argument.

- `floor(0.4)` gives `0`
- `floor(-0.6)` gives `-1`

#### `sqrt`

Returns the positive square root of the number.

```text
sqrt(number: number) → number
```

Also callable as `receiver.sqrt(…)`, with the receiver as the first argument.

- `sqrt(4)` gives `2`
- `sqrt(7)` gives `2.6457513110645905905`

#### `cbrt`

Returns the cube root of the number.

```text
cbrt(number: number) → number
```

Also callable as `receiver.cbrt(…)`, with the receiver as the first argument.

- `cbrt(9)` gives `2.0800838230519041145`
- `cbrt(64)` gives `4`

#### `exp`

Returns e^x, where x is the argument, and e is Euler's number (2.718…), the base of the natural logarithm.

```text
exp(number: number) → number
```

Also callable as `receiver.exp(…)`, with the receiver as the first argument.

- `exp(1)` gives `2.7182818284590452354`
- `exp(-1)` gives `0.3678794411714423216`

#### `ln`

Returns the natural logarithm of the number.

```text
ln(number: number) → number
```

Also callable as `receiver.ln(…)`, with the receiver as the first argument.

- `ln(2.718281828459045)` gives `0.99999999999999991342`
- `ln(10)` gives `2.302585092994045684`

#### `log10`

Returns the base 10 logarithm of the number.

```text
log10(number: number) → number
```

Also callable as `receiver.log10(…)`, with the receiver as the first argument.

- `log10(10)` gives `1`
- `log10(100000)` gives `5`

#### `log2`

Returns the base 2 logarithm of the number.

```text
log2(number: number) → number
```

Also callable as `receiver.log2(…)`, with the receiver as the first argument.

- `log2(4)` gives `2`
- `log2(1024)` gives `10`

#### `sign`

Returns 1 if the number is positive, -1 if it is negative, and 0 if it is zero.

```text
sign(number: number) → number
```

Also callable as `receiver.sign(…)`, with the receiver as the first argument.

- `sign(-10)` gives `-1`
- `sign(10)` gives `1`

#### `pi`

Returns the ratio of a circle's circumference to its diameter.

```text
pi() → number
```

- `pi()` gives `3.1415926535897932385`

#### `e`

Returns the base of the natural logarithm.

```text
e() → number
```

- `e()` gives `2.7182818284590452354`

#### `toNumber`

Converts a value to a number; the number conversion for a function or operator that needs a number. Text is parsed, a boolean is 1 or 0 and a date is its Unix timestamp in milliseconds.

```text
toNumber(value: text | number | boolean | date) → number
```

Also callable as `receiver.toNumber(…)`, with the receiver as the first argument.

- `toNumber("2")` gives `2`
- `toNumber(now())` gives `1693418100000`
- `toNumber(true)` gives `1`

#### `formatNumber`

Formats the number as text: "commas" (the default) groups thousands, "usd" writes dollars, "humanize" abbreviates to K, M, B or T. The optional third argument, which fixes the decimal places, is a Fontana extension: Notion 2.0 is formatNumber(number, format).

```text
formatNumber(number: number, format?: text, places?: number) → text
```

Also callable as `receiver.formatNumber(…)`, with the receiver as the first argument.

- `formatNumber(1234567.891)` gives `"1,234,567.891"`
- `formatNumber(1234567.891, "commas", 2)` gives `"1,234,567.89"`
- `formatNumber(1234567.891, "humanize")` gives `"1.2M"`
- `formatNumber(-1234.5, "usd")` gives `"-$1,234.50"`
- `"Revenue: " + formatNumber(1234.5, "usd", 0)` gives `"Revenue: $1,235"`

### Dates

#### `now`

Returns the current date and time.

```text
now() → date
```

- `now()` gives `@August 30, 2023 5:55 PM`

#### `today`

Returns the current date without the time.

```text
today() → date
```

- `today()` gives `@August 30, 2023`

#### `minute`

Returns the minute of the date (0-59).

```text
minute(date: date) → number
```

Also callable as `receiver.minute(…)`, with the receiver as the first argument.

- `minute(parseDate("2023-07-10T17:35Z"))` gives `35`

#### `hour`

Returns the hour of the date (0-23).

```text
hour(date: date) → number
```

Also callable as `receiver.hour(…)`, with the receiver as the first argument.

- `hour(parseDate("2023-07-10T17:35Z"))` gives `17`

#### `day`

Returns the day of the week of the date, between 1 (Monday) and 7 (Sunday).

```text
day(date: date) → number
```

Also callable as `receiver.day(…)`, with the receiver as the first argument.

- `day(parseDate("2023-07-10T17:35Z"))` gives `1`

#### `date`

Returns the day of the month from the date (1-31).

```text
date(date: date) → number
```

Also callable as `receiver.date(…)`, with the receiver as the first argument.

- `date(parseDate("2023-07-10T17:35Z"))` gives `10`

#### `week`

Returns the ISO week of the year of the date (1-53).

```text
week(date: date) → number
```

Also callable as `receiver.week(…)`, with the receiver as the first argument.

- `week(parseDate("2023-01-02"))` gives `1`

#### `month`

Returns the month of the date (1-12).

```text
month(date: date) → number
```

Also callable as `receiver.month(…)`, with the receiver as the first argument.

- `month(parseDate("2023-07-10T17:35Z"))` gives `7`

#### `year`

Returns the year of the date.

```text
year(date: date) → number
```

Also callable as `receiver.year(…)`, with the receiver as the first argument.

- `year(now())` gives `2023`

#### `dateAdd`

Adds time to the date; the unit is "years", "quarters", "months", "weeks", "days", "hours" or "minutes".

```text
dateAdd(date: date, amount: number, unit: text) → date
```

Also callable as `receiver.dateAdd(…)`, with the receiver as the first argument.

- `dateAdd(now(), 1, "days")` gives `@August 31, 2023 5:55 PM`
- `dateAdd(now(), 2, "months")` gives `@October 30, 2023 5:55 PM`
- `dateAdd(now(), 3, "years")` gives `@August 30, 2026 5:55 PM`

#### `dateSubtract`

Subtracts time from the date; the unit is "years", "quarters", "months", "weeks", "days", "hours" or "minutes".

```text
dateSubtract(date: date, amount: number, unit: text) → date
```

Also callable as `receiver.dateSubtract(…)`, with the receiver as the first argument.

- `dateSubtract(now(), 1, "days")` gives `@August 29, 2023 5:55 PM`
- `dateSubtract(now(), 2, "months")` gives `@June 30, 2023 5:55 PM`
- `dateSubtract(now(), 3, "years")` gives `@August 30, 2020 5:55 PM`

#### `dateBetween`

Returns the difference between two dates as whole units, first date minus second, truncated toward zero.

```text
dateBetween(date: date, other: date, unit: text) → number
```

Also callable as `receiver.dateBetween(…)`, with the receiver as the first argument.

- `dateBetween(now(), parseDate("2022-09-07"), "days")` gives `357`
- `dateBetween(parseDate("2030-01-01"), now(), "years")` gives `6`

#### `dateRange`

Returns the date range from a start date to an end date, as the two-item list [start, end]; dateStart() and dateEnd() read its ends.

```text
dateRange(start: date, end: date) → list<date>
```

Also callable as `receiver.dateRange(…)`, with the receiver as the first argument.

- `dateRange(parseDate("2023-07-10"), parseDate("2023-07-20"))` gives `[@July 10, 2023, @July 20, 2023]`

#### `dateStart`

Returns the start of a date range; a plain date is its own start.

```text
dateStart(range: list<date>) → date
dateStart(date: date) → date
```

Also callable as `receiver.dateStart(…)`, with the receiver as the first argument.

- `dateStart(dateRange(parseDate("2023-07-10"), parseDate("2023-07-20")))` gives `@July 10, 2023`
- `dateStart(now())` gives `@August 30, 2023 5:55 PM`

#### `dateEnd`

Returns the end of a date range; a plain date is its own end.

```text
dateEnd(range: list<date>) → date
dateEnd(date: date) → date
```

Also callable as `receiver.dateEnd(…)`, with the receiver as the first argument.

- `dateEnd(dateRange(parseDate("2023-07-10"), parseDate("2023-07-20")))` gives `@July 20, 2023`

#### `timestamp`

Returns the Unix timestamp of the date: the milliseconds elapsed since January 1, 1970 UTC.

```text
timestamp(date: date) → number
```

Also callable as `receiver.timestamp(…)`, with the receiver as the first argument.

- `timestamp(now())` gives `1693418100000`

#### `fromTimestamp`

Returns the date from the given Unix timestamp in milliseconds.

```text
fromTimestamp(timestamp: number) → date
```

Also callable as `receiver.fromTimestamp(…)`, with the receiver as the first argument.

- `fromTimestamp(1689024900000)` gives `@July 10, 2023 9:35 PM`

#### `parseDate`

Returns the date parsed according to the ISO 8601 standard, in UTC; with a format, parsed with the Moment tokens YYYY, YY (00-68 is 2000-2068), MMMM, MMM, MM, M, DD, D, Do, dddd, ddd, HH, H, hh, h (with A or a), mm, m, ss, s, SSS, A, a and [literal] text. The format needs the year; a missing month or day is the first, a missing time is midnight. Text that does not match the format fails the run.

```text
parseDate(text: text) → date
parseDate(text: text, format: text) → date
```

Also callable as `receiver.parseDate(…)`, with the receiver as the first argument.

- `parseDate("2022-01-01")` gives `@January 1, 2022`
- `parseDate("2022-01-01T00:00Z")` gives `@January 1, 2022`
- `parseDate("30/09/2026", "DD/MM/YYYY")` gives `@September 30, 2026`
- `parseDate("30 Sep 2026 5:55 PM", "D MMM YYYY h:mm A")` gives `@September 30, 2026 5:55 PM`

#### `formatDate`

Formats the date with Moment tokens: YYYY, YY, Y (year), Q (quarter), MMMM, MMM, MM, M (month), DD, D, Do (day of month), DDDD, DDD (day of year), dddd, ddd, dd, d (weekday; d is 0 for Sunday), E (ISO weekday), WW, W (ISO week), HH, H (hour 0-23), hh, h (hour 1-12), mm, m (minute), ss, s (second), SSS (millisecond), A, a (AM/PM, am/pm), Z, ZZ (offset), X, x (Unix seconds, milliseconds). Text in [brackets] is written as is; any other letter is an error.

```text
formatDate(date: date, format: text) → text
```

Also callable as `receiver.formatDate(…)`, with the receiver as the first argument.

- `formatDate(now(), "MMMM D, Y")` gives `"August 30, 2023"`
- `formatDate(now(), "MM/DD/YYYY")` gives `"08/30/2023"`
- `formatDate(now(), "h:mm A")` gives `"5:55 PM"`

### Lists

#### `at`

Returns the value at the specified index in a list.

```text
at(list, index)
```

Also callable as `receiver.at(…)`, with the receiver as the first argument.

- `at([1, 2, 3], 1)` gives `2`
- `[1, 2, 3].at(1)` gives `2`

#### `first`

Returns the first item in the list.

```text
first(list)
```

Also callable as `receiver.first(…)`, with the receiver as the first argument.

- `first([1, 2, 3])` gives `1`
- `[1, 2, 3].first()` gives `1`

#### `last`

Returns the last item in the list.

```text
last(list)
```

Also callable as `receiver.last(…)`, with the receiver as the first argument.

- `last([1, 2, 3])` gives `3`
- `[1, 2, 3].last()` gives `3`

#### `slice`

Returns the items of the list from the provided start index (inclusive) to the end index (exclusive).

```text
slice(list, start, end)
```

Also callable as `receiver.slice(…)`, with the receiver as the first argument.

- `slice([1, 2, 3], 1, 2)` gives `[2]`
- `slice(["a", "b", "c"], 1)` gives `["b", "c"]`

#### `concat`

Returns the concatenation of multiple lists. The text form concat(text, …), which joins text, is a Fontana extension: Notion 2.0 joins text with + or join().

```text
concat(list, …)
concat(text, …)
```

Also callable as `receiver.concat(…)`, with the receiver as the first argument.

- `concat([1, 2], [3, 4])` gives `[1, 2, 3, 4]`
- `concat(["a", "b"], ["c", "d"])` gives `["a", "b", "c", "d"]`
- `concat("dog", "go")` gives `"doggo"`

#### `sort`

Returns the list in sorted order.

```text
sort(list)
```

Also callable as `receiver.sort(…)`, with the receiver as the first argument.

- `sort([3, 1, 2])` gives `[1, 2, 3]`
- `["b", "c", "a"].sort()` gives `["a", "b", "c"]`

#### `reverse`

Returns the reversed list.

```text
reverse(list)
```

Also callable as `receiver.reverse(…)`, with the receiver as the first argument.

- `reverse(["green", "eggs", "ham"])` gives `["ham", "eggs", "green"]`

#### `join`

Returns the values of the list with the joiner placed in between each of the values.

```text
join(list, joiner)
```

Also callable as `receiver.join(…)`, with the receiver as the first argument.

- `join(["a", "b", "c"], ", ")` gives `"a, b, c"`
- `join(["dog", "go"], "")` gives `"doggo"`

#### `split`

Returns the list of values created by separating a text input at a separator.

```text
split(text, separator)
```

Also callable as `receiver.split(…)`, with the receiver as the first argument.

- `split("apple,pear,orange", ",")` gives `["apple", "pear", "orange"]`

#### `unique`

Returns the list of unique values in the input list.

```text
unique(list)
```

Also callable as `receiver.unique(…)`, with the receiver as the first argument.

- `unique([1, 1, 2])` gives `[1, 2]`
- `["a", "b", "a"].unique()` gives `["a", "b"]`

#### `includes`

Returns true if the list contains the specified value, and false otherwise.

```text
includes(list, value)
```

Also callable as `receiver.includes(…)`, with the receiver as the first argument.

- `includes(["a", "b", "c"], "b")` gives `true`
- `includes([1, 2, 3], 4)` gives `false`

#### `find`

Returns the first item in the list for which the condition evaluates to true.

```text
find(list, condition)
```

Also callable as `receiver.find(…)`, with the receiver as the first argument.

- `find(["a", "b", "c"], current == "b")` gives `"b"`
- `[1, 2, 3].find(current > 1)` gives `2`

#### `findIndex`

Returns the index of the first item in the list for which the condition is true, or -1 when none is.

```text
findIndex(list, condition)
```

Also callable as `receiver.findIndex(…)`, with the receiver as the first argument.

- `findIndex(["a", "b", "c"], current == "b")` gives `1`
- `[1, 2, 3].findIndex(current > 5)` gives `-1`

#### `filter`

Returns the values in the list for which the condition is true.

```text
filter(list, condition)
```

Also callable as `receiver.filter(…)`, with the receiver as the first argument.

- `filter([1, 2, 3], current > 1)` gives `[2, 3]`
- `filter(["a", "b", "c"], current == "a")` gives `["a"]`

#### `some`

Returns true if any item in the list satisfies the given condition, and false otherwise.

```text
some(list, condition)
```

Also callable as `receiver.some(…)`, with the receiver as the first argument.

- `some([1, 2, 3], current == 2)` gives `true`
- `some(["a", "b", "c"], current.length() > 2)` gives `false`

#### `every`

Returns true if every item in the list satisfies the given condition, and false otherwise.

```text
every(list, condition)
```

Also callable as `receiver.every(…)`, with the receiver as the first argument.

- `every([1, 2, 3], current > 0)` gives `true`
- `every(["a", "b", "c"], current == "b")` gives `false`

#### `map`

Returns the list populated with the results of calling the expression on every item in the input list.

```text
map(list, expression)
```

Also callable as `receiver.map(…)`, with the receiver as the first argument.

- `map([1, 2, 3], current + 1)` gives `[2, 3, 4]`
- `map([1, 2, 3], current + index)` gives `[1, 3, 5]`
- `[1, 2, 3].map(current * 2)` gives `[2, 4, 6]`

#### `flat`

Flattens a list of lists into a single list.

```text
flat(list)
```

Also callable as `receiver.flat(…)`, with the receiver as the first argument.

- `flat([1, 2, 3])` gives `[1, 2, 3]`
- `flat([[1, 2], [3, 4]])` gives `[1, 2, 3, 4]`

#### `count`

Returns the number of items in the list.

```text
count(list)
```

Also callable as `receiver.count(…)`, with the receiver as the first argument.

- `count([1, 2, 3])` gives `3`
- `[].count()` gives `0`

#### `splice`

Returns the list with the given number of items removed at the start index and the given values inserted there.

```text
splice(list, start, deleteCount, value, …)
```

Also callable as `receiver.splice(…)`, with the receiver as the first argument.

- `splice([1, 2, 3], 1, 1, "X")` gives `[1, "X", 3]`
- `[1, 2, 3].splice(0, 2)` gives `[3]`

### Statements

#### `setProp`

Sets a field on every row to the value of an expression; a new name adds the field. On context() it sets a context value instead; chained on insertRow() it sets a field of the inserted row from an expression that reads the current row. In a view formula it changes only the text the view shows for an existing field; the stored value stays.

```text
setProp(name, value)
context().setProp(name, value)
insertRow().setProp(name, value)
```

Also callable as `receiver.setProp(…)`, with the receiver as the first argument. Statement position only.

- `setProp("Side", prop("Side").upper())` — Every row with Side in upper case
- `setProp("price", prop("price").sum())` — Every group row with price set to the sum of its members
- `context().setProp("highestPrice", 0)` — Rows unchanged; context highestPrice is 0
- `insertRow().setProp("leg", "B").setProp("qty", 0 - prop("qty"))` — Every row followed by a copy whose leg is B and whose qty is the row's qty negated

#### `unsetProp`

Removes a field from every row.

```text
unsetProp(name)
```

Statement position only. Operation formulas only.

- `unsetProp("expired")` — Every row without the expired field

#### `keepProps`

Keeps only the named fields on every row, in that order, and removes every other field.

```text
keepProps(name, …)
```

Statement position only. Operation formulas only.

- `keepProps("owner", "ISIN")` — Every row with only the owner and ISIN fields

#### `insertRow`

Adds a copy of the current row, as it stands at that point, directly after it; chained .setProp(name, value) calls set fields on the copy from expressions that read the current row, and every other cell is copied. Allowed inside if() and do(); the statement never runs over the rows it inserted.

```text
insertRow()
```

Statement position only. Operation formulas only.

- `insertRow().setProp("leg", "B")` — Every row followed by a copy of itself with leg set to B
- `if(prop("qty") > 100, insertRow().setProp("qty", prop("qty") - 100))` — Rows over 100 are followed by a copy holding the excess; the other rows pass through alone
- `do(insertRow().setProp("leg", "A"), insertRow().setProp("leg", "B"), dropRow())` — Every row is replaced by two copies, leg A then leg B

#### `splitRows`

Emits one copy of every row per item of the list, the item written under name and every other field copied; an empty list drops the row. An item that is an object is carried whole and read afterwards with .prop. A row-set statement like groupBy: not allowed inside if() or do().

```text
splitRows(list, name)
```

Statement position only. Operation formulas only.

- `splitRows(prop("tags"), "tag")` — One row per tag, with the tag under tag and the other fields copied; a row with no tags is dropped
- `splitRows(prop("ISINs").split(";"), "ISIN")` — One row per semicolon-separated ISIN
- `splitRows(prop("rows"), "item")` — One row per object of the rows list, the object under item; prop("item").prop("isin") then reads one of its fields

#### `appendRows`

Adds every row of a named table after the current rows, each with the data styles that table carries. The row type afterwards is the merge of the current rows and the table's columns, so a column only one side has reads empty on the other. A row-set statement like groupBy: not allowed inside if(), do() or each().

```text
appendRows(table)
```

Statement position only. Operation formulas only.

- `appendRows(inputs().prop("corrections"))` — The current rows, then every row of the corrections table

#### `spreadProps`

Writes one level of an object's fields as columns of the row, named by their keys. Chained .prefix(text) joins a text literal onto each name; chained .value(expression) is evaluated per field with current bound to that field's value and becomes the cell. A plain prop("x") argument removes that column after the spread. Empty adds nothing. A collision with an existing column, a non-object value, or an empty or reserved name fails. A row-set statement like groupBy: not allowed inside if(), do() or each().

```text
spreadProps(object)
```

Statement position only. Operation formulas only.

- `spreadProps(prop("price"))` — The fields of price as columns; the price column is removed
- `spreadProps(prop("price")).prefix("p.")` — The fields of price as columns named p.value, p.ccy, …; the price column is removed
- `spreadProps(prop("properties")).value(ifs(current.prop("type") == "number", current.prop("number"), current))` — Each property unwrapped by its type, as a column named by its key; the properties column is removed

#### `each`

Runs a statement once per item of a list, on the same row, with current bound to the item and index to its zero-based position; an empty list or an empty value runs it zero times and a value that is not a list fails the run. The body may set and unset row fields, raise an exception, write context, branch with if() and do(), and nest another each(); raiseException() needs both a field and a key there, and the key must identify the row as well as the item, because it is the whole identity of the ticket across the node. current is read-only and the list is not written back, so dropRow(), filter(), keepProps() and the row-set statements cannot run inside it.

```text
each(list, statement)
```

Also callable as `receiver.each(…)`, with the receiver as the first argument. Statement position only. Operation formulas only.

- `each(prop("legs"), if(empty(current.prop("ISIN")), raiseException("legs", concat(prop("tradeId"), ":", format(index))).setProp("message", "Leg has no ISIN")))` — One ticket on the legs column per leg with no ISIN, keyed by the trade and the leg's position; every row stays in the output
- `prop("legs").each(context().setProp("lastISIN", current.prop("ISIN")))` — Rows unchanged; the context value lastISIN is the ISIN of the last row's last leg

#### `dropRow`

Leaves the current row out of the output. A bare dropRow() drops every row.

```text
dropRow()
```

Statement position only. Operation formulas only.

- `if(prop("expired").equal(1), dropRow())` — Rows where expired is 1 are dropped

#### `filter`

With one argument, keeps the rows where the condition is true. The two-argument form is the list function.

```text
filter(condition)
```

Statement position only. Operation formulas only.

- `filter(prop("expired") != 1)` — Rows where expired is not 1

#### `sortBy`

Stable-sorts every row by the keys, first key primary; a key is ascending unless wrapped in desc(), and empties sort last in both directions.

```text
sortBy(key, …)
```

Statement position only. Operation formulas only.

- `sortBy(prop("owner"), desc(prop("price")))` — Rows by owner ascending, then price descending

#### `desc`

Sorts a sortBy key descending. Valid only as a sortBy argument.

```text
desc(key)
```

Operation formulas only.

- `sortBy(desc(prop("price")))` — Rows by price descending

#### `groupBy`

Emits one row per key tuple in first-seen order; every field becomes the list of member values, plus __groupKey (the key values) and __groupIndices (the member indices).

```text
groupBy(key, …)
```

Statement position only. Operation formulas only.

- `groupBy(prop("owner"), prop("ISIN"))` — One row per owner and ISIN: { __groupKey: ["zoltan", "SOMEISIN"], __groupIndices: [0, 1], owner: ["zoltan", "zoltan"], ISIN: ["SOMEISIN", "SOMEISIN"], price: [3, 6] }

#### `do`

Runs statements left to right on the same row.

```text
do(statement, …)
```

Statement position only.

- `if(prop("owner").empty(), do(raiseException().setProp("message", "Owner is missing"), dropRow()))` — Rows without an owner raise an exception and are dropped

#### `if`

With statement branches, runs the first branch on rows where the condition is true and the second, when present, on the others; rows without a branch pass through.

```text
if(condition, statement, statement)
```

Statement position only.

- `if(prop("Created by").equal("buy"), setProp("Created by", "BUY"), setProp("Created by", "SELL"))` — Created by is "BUY" on buy rows and "SELL" on the others

### Context and named tables

#### `context`

Returns the formula context, one object for the whole node: it starts empty in the node's first statement and keeps every value set before, across the node's calls. Read it with .prop and write it with .setProp; context(name) is context().prop(name).

```text
context()
context(name)
```

Operation formulas only.

- `context().prop("highestPrice")` — The highestPrice context value
- `context("highestPrice")` — The same value, in the short form

#### `inputs`

Returns the node's named tables: one per wire into it, plus each table a call defined earlier in the node; .prop(handle) is the table named handle, and inputs(handle) is inputs().prop(handle).

```text
inputs()
inputs(handle)
```

Operation formulas only.

- `inputs().prop("ibor_valuations")` — The ibor_valuations table
- `inputs("ibor_valuations")` — The same table, in the short form

#### `rowIndex`

Returns the current row's zero-based position in the row array entering the statement. Inside a list callback or an each() body index is still the item's position and rowIndex() is still the row's.

```text
rowIndex()
```

Operation formulas only.

- `setProp("n", rowIndex() + 1)` — Every row numbered from 1 in arrival order
- `setProp("b", inputs().prop("b").rows().at(rowIndex()).prop("value"))` — Each row merged with the table row in the same position; empty past the end of the table

#### `input`

Returns the node's own incoming rows as a table; .rows() is every row in table order. A node condition reads its incoming dataset through it.

```text
input()
```

Operation formulas only.

- `input().rows().some(current.prop("SIDE").test("BUY"))` — true when any incoming row has SIDE BUY
- `input().rows().count() > 0` — true when the node has incoming rows

#### `prop`

Returns a field of the current row, of a table row, a context value, or a named table by its handle.

```text
prop(name)
row.prop(name)
context().prop(name)
inputs().prop(handle)
```

Also callable as `receiver.prop(…)`, with the receiver as the first argument.

- `prop("price") * 2` — Twice the row's price
- `inputs().prop("ibor_valuations").find("ISIN", prop("ISIN")).prop("value")` — value of the first ibor_valuations row whose ISIN matches; empty on a miss

#### `getProp`

Returns a field of the current row or of a table row; the same read as prop.

```text
getProp(name)
row.getProp(name)
```

Also callable as `receiver.getProp(…)`, with the receiver as the first argument.

- `getProp("price")` — The row's price

#### `find`

On a named table, returns the first row in table order whose column equals the value under ==, or empty when none matches.

```text
table.find(column, value)
```

Also callable as `receiver.find(…)`, with the receiver as the first argument. Operation formulas only.

- `inputs().prop("ibor_valuations").find("ISIN", prop("ISIN"))` — The first ibor_valuations row whose ISIN matches; empty on a miss

#### `findAll`

On a named table, returns every row in table order whose column equals the value under ==.

```text
table.findAll(column, value)
```

Also callable as `receiver.findAll(…)`, with the receiver as the first argument. Operation formulas only.

- `inputs().prop("ibor_valuations").findAll("ISIN", prop("ISIN")).map(current.prop("value")).sum()` — Sum of value over every matching ibor_valuations row

#### `rows`

On a named table, returns every row in table order.

```text
table.rows()
```

Also callable as `receiver.rows(…)`, with the receiver as the first argument. Operation formulas only.

- `inputs().prop("ibor_valuations").rows().count()` — Number of rows in the ibor_valuations table

#### `exceptions`

In a node condition, returns the exceptions raised in this build anywhere upstream of a table's wire (the node wired in and every node before it, each counted once), counted by severity: .prop("info") (levels 1 and 2), .prop("warning") (level 3) and .prop("error") (levels 4 and 5). On input() the counts cover everything upstream of the node, through every wire.

```text
table.exceptions()
```

Also callable as `receiver.exceptions(…)`, with the receiver as the first argument. Operation formulas only.

- `input().exceptions().prop("warning") == 0 and input().exceptions().prop("error") == 0` — true when nothing upstream of the node raised a warning or error exception
- `inputs().prop("trades").exceptions().prop("error") == 0` — true when nothing upstream of the trades wire raised an error exception

### Exceptions

#### `raiseException`

Records an exception for the current row and keeps the row; field pins the ticket's column and key (text or number; an empty key is the blank text "") its identity across runs.

```text
raiseException()
raiseException(field)
raiseException(field, key)
```

Operation formulas only.

- `if(prop("owner").empty(), raiseException().setProp("message", "Owner is missing").setProp("severityLevel", 3))` — Rows without an owner raise a level 3 exception and stay in the output
- `raiseException("price", concat(prop("owner"), prop("ISIN"))).setProp("type", "Pricing")` — One Pricing ticket on the price column per owner and ISIN

#### `setProp`

On an exception, sets an exception field: "message", "severityLevel" (alias "severity", an integer 1 through 5), "type", or any other Exception Management field (status, assignee, custom properties) as text.

```text
raiseException().setProp(name, value)
```

Also callable as `receiver.setProp(…)`, with the receiver as the first argument. Operation formulas only.

```text
raiseException()
  .setProp("message", "Owner is missing")
  .setProp("severity", 3)
  .setProp("type", "Data quality")
  .setProp("status", "investigating")
```

— An exception with message "Owner is missing", severity level 3, type "Data quality" and status investigating

### Styles and viewer

#### `setStyle`

Sets one style key on one field of the current row; a later write of the same key on the same field wins. Chains with .setStyle() and .setRowStyle().

```text
setStyle(field, key, value)
style.setStyle(field, key, value)
```

Also callable as `receiver.setStyle(…)`, with the receiver as the first argument. Statement position only.

- `if(test(prop("Fund ID"), "14$"), setStyle("Fund ID", "background", "lime"))` — Fund ID cells that end in 14 get a lime background
- `setStyle("Reporting GP", "icon", "thumbsup").setStyle("Reporting GP", "text_color", "indigo")` — Every Reporting GP cell shows the thumbsup icon in indigo text

#### `setRowStyle`

Sets one style key on the current row itself, with the keys setStyle takes; the row's text styles reach every field that does not set that key itself.

```text
setRowStyle(key, value)
style.setRowStyle(key, value)
```

Also callable as `receiver.setRowStyle(…)`, with the receiver as the first argument. Statement position only.

- `if(prop("Done"), setRowStyle("strikethrough", true).setRowStyle("text_color", "gray"))` — Done rows are struck through in gray

#### `clearStyle`

Removes one style key from one field of the current row, or every style key on it when no key is given. Chains like setStyle.

```text
clearStyle(field)
clearStyle(field, key)
style.clearStyle(field, key)
```

Also callable as `receiver.clearStyle(…)`, with the receiver as the first argument. Statement position only.

- `if(prop("Settled"), clearStyle("Settlement Date"))` — A settled row keeps no style on its Settlement Date cell
- `clearStyle("Notional", "background")` — The Notional cell loses its background and keeps its other styles

#### `clearRowStyle`

Removes one style key from the current row itself, or every style key on the row when no key is given. Chains like setRowStyle.

```text
clearRowStyle()
clearRowStyle(key)
style.clearRowStyle(key)
```

Also callable as `receiver.clearRowStyle(…)`, with the receiver as the first argument. Statement position only.

- `if(prop("Status") == "Confirmed", clearRowStyle())` — A confirmed trade's row carries no row style

#### `me`

Returns the signed-in viewer's name, or empty where the view has no signed-in viewer.

```text
me() → text
```

View formulas only.

- `if(prop("Assignee").includes(me()), setRowStyle("background", "sky"))` — Rows assigned to the viewer get a sky background

#### `optionColor`

Returns the colour token of the option the current row holds in a select, status or multi-select field (the first selected option that has a colour), or empty when it has none. The field is a text literal.

```text
optionColor(field: text) → text
```

View formulas only.

- `setStyle("Status", "dot", optionColor("Status"))` — Each Status cell shows a dot in its option's colour; an option without a colour shows none

## Worked examples

Each example is a formula, its input, and the exact output the interpreter produces.

### date-tour

```text
/* Dates are UTC and written as ISO-8601. now() and today() read the run's fixed
   clock (input "now": 2026-10-25T12:00Z). An empty date passes through every
   date function as empty. dateBetween truncates toward zero. The input field
   "when" is never written, so its cell leaves exactly as it arrived. */

setProp("next_month", dateAdd(prop("when"), 1, "months"))
setProp("minus_week", prop("when").dateSubtract(1, "weeks"))
setProp("days_until_now", dateBetween(now(), prop("when"), "days"))
setProp("years_to_2030", dateBetween(parseDate("2030-01-01"), now(), "years"))
setProp("pretty", formatDate(prop("when"), "MMMM D, Y"))
setProp("us", prop("when").formatDate("MM/DD/YYYY"))
setProp("clock", formatDate(prop("when"), "h:mm A"))
setProp("y", year(prop("when")))
setProp("m", month(prop("when")))
setProp("d", date(prop("when")))
setProp("weekday", day(prop("when")))
setProp("wk", week(prop("when")))
setProp("hh", hour(prop("when")))
setProp("mi", minute(prop("when")))
setProp("stamp", timestamp(prop("when")))
setProp("today_iso", today())
setProp("parsed", parseDate("2022-01-01"))
setProp("from_stamp", fromTimestamp(1689024900000))
```

Input fields: `when: date`, `label: text`.

Clock: `now()` is `2026-10-25T12:00:00Z`.

Input rows:

```json
[
  {"when":"2026-01-31","label":"month end"},
  {"when":"2025-12-24T18:30:00Z","label":"evening"},
  {"when":null,"label":"no date"}
]
```

Output rows:

```json
[
  {"when":"2026-01-31","label":"month end","next_month":"2026-02-28T00:00:00.000Z","minus_week":"2026-01-24T00:00:00.000Z","days_until_now":267,"years_to_2030":3,"pretty":"January 31, 2026","us":"01/31/2026","clock":"12:00 AM","y":2026,"m":1,"d":31,"weekday":6,"wk":5,"hh":0,"mi":0,"stamp":1769817600000,"today_iso":"2026-10-25T00:00:00.000Z","parsed":"2022-01-01T00:00:00.000Z","from_stamp":"2023-07-10T21:35:00.000Z"},
  {"when":"2025-12-24T18:30:00Z","label":"evening","next_month":"2026-01-24T18:30:00.000Z","minus_week":"2025-12-17T18:30:00.000Z","days_until_now":304,"years_to_2030":3,"pretty":"December 24, 2025","us":"12/24/2025","clock":"6:30 PM","y":2025,"m":12,"d":24,"weekday":3,"wk":52,"hh":18,"mi":30,"stamp":1766601000000,"today_iso":"2026-10-25T00:00:00.000Z","parsed":"2022-01-01T00:00:00.000Z","from_stamp":"2023-07-10T21:35:00.000Z"},
  {"when":null,"label":"no date","next_month":null,"minus_week":null,"days_until_now":null,"years_to_2030":3,"pretty":null,"us":null,"clock":null,"y":null,"m":null,"d":null,"weekday":null,"wk":null,"hh":null,"mi":null,"stamp":null,"today_iso":"2026-10-25T00:00:00.000Z","parsed":"2022-01-01T00:00:00.000Z","from_stamp":"2023-07-10T21:35:00.000Z"}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### do-raise-and-drop

```text
/* do() runs its statements left to right on the same row: raise the
   exception, then drop the row. The exception outlives the dropped row. */

if(
  prop("owner").empty(),
  do(
    raiseException("owner")
      .setProp("message", "Owner is missing")
      .setProp("severityLevel", 3),
    dropRow()
  )
)
```

Input fields: `owner: text`, `ISIN: text`, `price: number`.

Input rows:

```json
[
  {"owner":"zoltan","ISIN":"A","price":3},
  {"owner":"","ISIN":"B","price":2},
  {"owner":"ann","ISIN":"C","price":4}
]
```

Output rows:

```json
[
  {"owner":"zoltan","ISIN":"A","price":3},
  {"owner":"ann","ISIN":"C","price":4}
]
```

Exceptions raised:

```json
[
  {"inputRowIndex":1,"field":"owner","message":"Owner is missing","severityLevel":3}
]
```

Final context:

```json
{}
```

### each-check-every-leg

```text
# One ticket per leg with no ISIN, on the trade row that holds the legs. The
# key is the trade and the leg's position, so every leg keeps its own ticket.
each(
  prop("legs"),
  if(
    empty(current.prop("ISIN")),
    raiseException("legs", concat(prop("tradeId"), ":", format(index)))
      .setProp("message", "Leg has no ISIN")
      .setProp("severity", 3)
  )
)

# The legs stay as they arrived: an object is read, never written back.
setProp("legCount", prop("legs").count())

setProp("notional", prop("legs").map(current.prop("notional")).sum())
```

Input fields: `tradeId: text`, `legs: list<object>`.

Input rows:

```json
[
  {"tradeId":"T-1","legs":[{"ISIN":"SOMEISIN","notional":1000},{"ISIN":"","notional":250}]},
  {"tradeId":"T-2","legs":[{"ISIN":"OTHERISIN","notional":400}]}
]
```

Output rows:

```json
[
  {"tradeId":"T-1","legs":[{"ISIN":"SOMEISIN","notional":1000},{"ISIN":"","notional":250}],"legCount":2,"notional":1250},
  {"tradeId":"T-2","legs":[{"ISIN":"OTHERISIN","notional":400}],"legCount":1,"notional":400}
]
```

Exceptions raised:

```json
[
  {"inputRowIndex":0,"field":"legs","key":"T-1:1","message":"Leg has no ISIN","severityLevel":3}
]
```

### filter-vs-dropRow

```text
/* filter(condition) keeps the rows where the condition is true (Notion polarity).
   filter-vs-dropRow-equivalent writes the same row set with if(..., dropRow()). */

filter(prop("expired") != 1)
```

Input fields: `ISIN: text`, `expired: number`, `price: number`.

Input rows:

```json
[
  {"ISIN":"A","expired":0,"price":3},
  {"ISIN":"B","expired":1,"price":6},
  {"ISIN":"C","expired":0,"price":10},
  {"ISIN":"D","expired":1,"price":2},
  {"ISIN":"E","expired":0,"price":4}
]
```

Output rows:

```json
[
  {"ISIN":"A","expired":0,"price":3},
  {"ISIN":"C","expired":0,"price":10},
  {"ISIN":"E","expired":0,"price":4}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### filter-vs-dropRow-equivalent

```text
/* The same row set as filter-vs-dropRow: drop where the condition is true. */

if(prop("expired").equal(1), dropRow())
```

Input fields: `ISIN: text`, `expired: number`, `price: number`.

Input rows:

```json
[
  {"ISIN":"A","expired":0,"price":3},
  {"ISIN":"B","expired":1,"price":6},
  {"ISIN":"C","expired":0,"price":10},
  {"ISIN":"D","expired":1,"price":2},
  {"ISIN":"E","expired":0,"price":4}
]
```

Output rows:

```json
[
  {"ISIN":"A","expired":0,"price":3},
  {"ISIN":"C","expired":0,"price":10},
  {"ISIN":"E","expired":0,"price":4}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### groupBy-then-copy-key

```text
# The group helpers are formula-local: copy __groupKey under another name
# before the output drops it. Comments run from # to the end of the line.

groupBy(prop("owner"))

setProp("groupKey", prop("__groupKey")) # a list even with one key field
setProp("members", prop("__groupIndices").count())

# Aggregate the member lists back to one value per group.
setProp("owner", prop("owner").first())
setProp("price", prop("price").sum())
```

Input fields: `owner: text`, `price: number`.

Input rows:

```json
[
  {"owner":"zoltan","price":3},
  {"owner":"ann","price":10},
  {"owner":"zoltan","price":6},
  {"owner":"ann","price":4},
  {"owner":"","price":2}
]
```

Output rows:

```json
[
  {"owner":"zoltan","price":9,"groupKey":["zoltan"],"members":2},
  {"owner":"ann","price":14,"groupKey":["ann"],"members":2},
  {"owner":"","price":2,"groupKey":[""],"members":1}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### highest-price-context

```text
/* Highest price via context: the spec's second Example program.
   The first write types the key; the scan finishes before the flag is set. */

context().setProp("highestPrice", 0)

if(
  prop("price") > context().prop("highestPrice"),
  context().setProp("highestPrice", prop("price"))
)

setProp("isHighest", prop("price") == context().prop("highestPrice"))
```

Input fields: `owner: text`, `price: number`.

Input rows:

```json
[
  {"owner":"zoltan","price":3},
  {"owner":"zoltan","price":6},
  {"owner":"ann","price":10},
  {"owner":"","price":2},
  {"owner":"ann","price":4}
]
```

Output rows:

```json
[
  {"owner":"zoltan","price":3,"isHighest":false},
  {"owner":"zoltan","price":6,"isHighest":false},
  {"owner":"ann","price":10,"isHighest":true},
  {"owner":"","price":2,"isHighest":false},
  {"owner":"ann","price":4,"isHighest":false}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{"highestPrice":10}
```

### inputs-enrich

```text
/* Enrich from a second wire: first match in table order, empty on a miss,
   an explicit miss value with let, every match with findAll, and rows(). */

setProp("ibor_value", inputs().prop("ibor_valuations").find("ISIN", prop("ISIN")).prop("value"))

setProp(
  "ibor_or_minus_one",
  let(
    hit,
    inputs().prop("ibor_valuations").find("ISIN", prop("ISIN")),
    if(empty(hit), -1, hit.prop("value"))
  )
)

setProp("hits", inputs().prop("ibor_valuations").findAll("ISIN", prop("ISIN")).count())

setProp("table_size", inputs().prop("ibor_valuations").rows().count())
```

Input fields: `ISIN: text`, `price: number`.

Table `ibor_valuations` (`ISIN: text`, `value: number`):

```json
[
  {"ISIN":"SOMEISIN","value":1.5},
  {"ISIN":"X","value":7},
  {"ISIN":"X","value":8}
]
```

Input rows:

```json
[
  {"ISIN":"SOMEISIN","price":3},
  {"ISIN":"Y","price":2},
  {"ISIN":"X","price":4}
]
```

Output rows:

```json
[
  {"ISIN":"SOMEISIN","price":3,"ibor_value":1.5,"ibor_or_minus_one":1.5,"hits":1,"table_size":3},
  {"ISIN":"Y","price":2,"ibor_value":null,"ibor_or_minus_one":-1,"hits":0,"table_size":3},
  {"ISIN":"X","price":4,"ibor_value":7,"ibor_or_minus_one":7,"hits":2,"table_size":3}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### insertRow-two-legs

```text
/* Replace every row by two legs. insertRow() copies the row as it stands at
   that point and the chained .setProp calls set fields on the copy, reading
   the current row; dropRow() then removes the original. */

do(
  insertRow().setProp("leg", "A"),
  insertRow().setProp("leg", "B").setProp("qty", 0 - prop("qty")),
  dropRow()
)

# Later statements see the inserted rows.
setProp("long", prop("qty") > 0)
```

Input fields: `trade: text`, `qty: number`.

Input rows:

```json
[
  {"trade":"T1","qty":100},
  {"trade":"T2","qty":40}
]
```

Output rows:

```json
[
  {"trade":"T1","qty":100,"leg":"A","long":true},
  {"trade":"T1","qty":-100,"leg":"B","long":false},
  {"trade":"T2","qty":40,"leg":"A","long":true},
  {"trade":"T2","qty":-40,"leg":"B","long":false}
]
```

Final context:

```json
{}
```

### normalise-drop-raise-group-aggregate

```text
/* Normalise, drop, raise, group, aggregate: the spec's first Example program. */

if(
  prop("Created by").equal("buy"),
  setProp("Created by", "BUY"),
  setProp("Created by", "SELL")
)

filter(prop("expired") != 1)

if(
  prop("owner").empty(),
  raiseException()
    .setProp("message", "Owner is missing")
    .setProp("severityLevel", 3)
)

groupBy(prop("owner"), prop("ISIN"))

setProp("owner", prop("owner").first())
setProp("ISIN", prop("ISIN").first())
setProp("price", prop("price").sum())
```

Input fields: `Created by: text`, `expired: number`, `owner: text`, `ISIN: text`, `price: number`.

Input rows:

```json
[
  {"Created by":"buy","expired":0,"owner":"zoltan","ISIN":"SOMEISIN","price":3},
  {"Created by":"sell","expired":0,"owner":"zoltan","ISIN":"SOMEISIN","price":6},
  {"Created by":"buy","expired":1,"owner":"ann","ISIN":"X","price":10},
  {"Created by":"sell","expired":0,"owner":"","ISIN":"Y","price":2},
  {"Created by":"buy","expired":0,"owner":"ann","ISIN":"X","price":4}
]
```

Output rows:

```json
[
  {"Created by":["BUY","SELL"],"expired":[0,0],"owner":"zoltan","ISIN":"SOMEISIN","price":9},
  {"Created by":["SELL"],"expired":[0],"owner":"","ISIN":"Y","price":2},
  {"Created by":["BUY"],"expired":[0],"owner":"ann","ISIN":"X","price":4}
]
```

Exceptions raised:

```json
[
  {"inputRowIndex":3,"message":"Owner is missing","severityLevel":3}
]
```

Final context:

```json
{}
```

### number-tour

```text
/* Numbers are Decimal.js while they are computed: round() is half away from
   zero (2.5 → 3, -2.5 → -3, 1.005 → 1.01 at two places), mod keeps the sign of
   the first operand, 5 / 10 is exactly 0.5 and 0.1 + 0.2 is exactly 0.3.
   Cells are written as JavaScript numbers. */

setProp("rounded", round(prop("a")))
setProp("rounded2", round(prop("a"), 2))
setProp("half_up", round(0.5))
setProp("half_down", round(-0.5))
setProp("hundreds", round(1234, -2))
setProp("modulo", mod(prop("a"), prop("b")))
setProp("remainder", 7 % prop("b"))
setProp("half", 5 / 10)
setProp("ratio", prop("a") / prop("b"))
setProp("cents", 0.1 + 0.2)
setProp("power", 2 ^ 2 ^ 3)
setProp("sum3", sum(prop("a"), prop("b"), 0.1))
setProp("min_ab", min(prop("a"), prop("b")))
setProp("max_ab", max(prop("a"), prop("b")))
setProp("mean_ab", mean(prop("a"), prop("b")))
setProp("median4", median([1, 2, 3], 4))
setProp("abs_a", abs(prop("a")))
setProp("sign_a", sign(prop("a")))
setProp("ceil_a", ceil(prop("a")))
setProp("floor_a", floor(prop("a")))
setProp("usd", formatNumber(prop("a"), "usd"))
setProp("commas", formatNumber(1234567.891))
setProp("parsed", toNumber("2") + 1)
```

Input fields: `a: number`, `b: number`.

Input rows:

```json
[
  {"a":2.5,"b":3},
  {"a":-2.5,"b":-3},
  {"a":1.005,"b":10}
]
```

Output rows:

```json
[
  {"a":2.5,"b":3,"rounded":3,"rounded2":2.5,"half_up":1,"half_down":-1,"hundreds":1200,"modulo":2.5,"remainder":1,"half":0.5,"ratio":0.8333333333333334,"cents":0.3,"power":256,"sum3":5.6,"min_ab":2.5,"max_ab":3,"mean_ab":2.75,"median4":2.5,"abs_a":2.5,"sign_a":1,"ceil_a":3,"floor_a":2,"usd":"$2.50","commas":"1,234,567.891","parsed":3},
  {"a":-2.5,"b":-3,"rounded":-3,"rounded2":-2.5,"half_up":1,"half_down":-1,"hundreds":1200,"modulo":-2.5,"remainder":1,"half":0.5,"ratio":0.8333333333333334,"cents":0.3,"power":256,"sum3":-5.4,"min_ab":-3,"max_ab":-2.5,"mean_ab":-2.75,"median4":2.5,"abs_a":2.5,"sign_a":-1,"ceil_a":-2,"floor_a":-3,"usd":"-$2.50","commas":"1,234,567.891","parsed":3},
  {"a":1.005,"b":10,"rounded":1,"rounded2":1.01,"half_up":1,"half_down":-1,"hundreds":1200,"modulo":1.005,"remainder":7,"half":0.5,"ratio":0.1005,"cents":0.3,"power":256,"sum3":11.105,"min_ab":1.005,"max_ab":10,"mean_ab":5.5025,"median4":2.5,"abs_a":1.005,"sign_a":1,"ceil_a":2,"floor_a":1,"usd":"$1.01","commas":"1,234,567.891","parsed":3}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### raise-with-field-and-key

```text
/* A keyed exception pinned to a column: the ticket follows the key across runs.
   severity is the same exception field as severityLevel. Extra Exception
   Management fields (status, assignee, custom properties) use the same
   setProp. Every row is still emitted. */

if(
  prop("price") < 0,
  raiseException("price", concat(prop("owner"), prop("ISIN")))
    .setProp("message", "Negative price")
    .setProp("severity", 4)
    .setProp("type", "pricing")
    .setProp("status", "investigating")
)
```

Input fields: `owner: text`, `ISIN: text`, `price: number`.

Input rows:

```json
[
  {"owner":"zoltan","ISIN":"SOMEISIN","price":-1},
  {"owner":"ann","ISIN":"X","price":4},
  {"owner":"ann","ISIN":"Y","price":-2.5}
]
```

Output rows:

```json
[
  {"owner":"zoltan","ISIN":"SOMEISIN","price":-1},
  {"owner":"ann","ISIN":"X","price":4},
  {"owner":"ann","ISIN":"Y","price":-2.5}
]
```

Exceptions raised:

```json
[
  {"inputRowIndex":0,"field":"price","key":"zoltanSOMEISIN","message":"Negative price","severityLevel":4,"type":"pricing","extraFields":{"status":"investigating"}},
  {"inputRowIndex":2,"field":"price","key":"annY","message":"Negative price","severityLevel":4,"type":"pricing","extraFields":{"status":"investigating"}}
]
```

Final context:

```json
{}
```

### sortBy-desc-with-empties

```text
/* Stable sort: owner ascending, then price descending; empties sort last
   in both directions, and equal keys keep their input order (ids 1 before 4). */

sortBy(prop("owner"), desc(prop("price")))
```

Input fields: `id: number`, `owner: text`, `price: number`.

Input rows:

```json
[
  {"id":1,"owner":"b","price":1},
  {"id":2,"owner":"a","price":null},
  {"id":3,"owner":"a","price":5},
  {"id":4,"owner":"b","price":1},
  {"id":5,"owner":"a","price":2}
]
```

Output rows:

```json
[
  {"id":3,"owner":"a","price":5},
  {"id":5,"owner":"a","price":2},
  {"id":2,"owner":"a","price":null},
  {"id":1,"owner":"b","price":1},
  {"id":4,"owner":"b","price":1}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### splitRows-one-per-tag

```text
# One row per tag: splitRows() emits a copy of the row per list item with
# the item under the new field; a row whose list is empty is dropped.

splitRows(prop("tags"), "tag")

setProp("tag", prop("tag").upper())
```

Input fields: `name: text`, `tags: list<text>`.

Input rows:

```json
[
  {"name":"a","tags":["x","y"]},
  {"name":"b","tags":[]},
  {"name":"c","tags":["z"]}
]
```

Output rows:

```json
[
  {"name":"a","tags":["x","y"],"tag":"X"},
  {"name":"a","tags":["x","y"],"tag":"Y"},
  {"name":"c","tags":["z"],"tag":"Z"}
]
```

Final context:

```json
{}
```

### spreadProps-price-fields

```text
# One level of an object as columns: spreadProps() writes the fields of
# price as value and ccy, and removes the price column because the
# argument is a plain column read.

spreadProps(prop("price"))
```

Input fields: `id: text`, `price: object`.

Input rows:

```json
[
  {"id":"p1","price":{"value":101.2,"ccy":"EUR"}},
  {"id":"p2","price":{"value":99.5,"ccy":"USD"}}
]
```

Output rows:

```json
[
  {"id":"p1","value":101.2,"ccy":"EUR"},
  {"id":"p2","value":99.5,"ccy":"USD"}
]
```

Final context:

```json
{}
```

### style-lineage-trade-consideration

```text
setStyle("Dirty Price", "background", "rose")

setRowStyle("bold", true)

setProp("Consideration", prop("Dirty Price") * prop("Quantity"))

setProp("Desk", if(prop("Quantity") > 0, "Rates", "Credit"))

setProp("Currency", "GBP")

clearRowStyle("bold")
```

Input fields: `ISIN: text`, `Dirty Price: number`, `Quantity: number`.

Input rows:

```json
[
  {"ISIN":"GB00B16NNR78","Dirty Price":101.25,"Quantity":500000},
  {"ISIN":"XS1234567890","Dirty Price":98.5,"Quantity":-250000}
]
```

Output rows:

```json
[
  {"ISIN":"GB00B16NNR78","Dirty Price":101.25,"Quantity":500000,"Consideration":50625000,"Desk":"Rates","Currency":"GBP"},
  {"ISIN":"XS1234567890","Dirty Price":98.5,"Quantity":-250000,"Consideration":-24625000,"Desk":"Credit","Currency":"GBP"}
]
```

### text-functions-tour

```text
/* Text functions: trim, padStart / padEnd (a number is formatted before padding,
   and a number pad becomes its text), regex replaceAll / match / test with
   JavaScript escapes written as "\\d", format, split / join, substring, replace. */

setProp("trimmed", prop("name").trim())
setProp("lowered", prop("name").lower())
setProp("padded", prop("code").padStart(5, 0))
setProp("padded_text", prop("name").trim().padEnd(8, "."))
setProp("pad_len", prop("name").trim().padStart(8, "!".length()))
setProp("digits_removed", replaceAll(concat(prop("name").trim(), " 123"), "\\d", ""))
setProp("matches", match(concat(prop("name").trim(), " 123 and 456"), "\\d+"))
setProp("starts_blank", test(prop("name"), "^\\s"))
setProp("label", format(prop("code")) + "-" + prop("name").trim().upper())
setProp("parts", prop("csv").split(","))
setProp("joined", prop("csv").split(",").reverse().join(" | "))
setProp("first_part", prop("csv").split(",").first())
setProp("has_pear", prop("csv").contains("pear"))
setProp("len", prop("name").length())
setProp("sub", substring(prop("name").trim(), 0, 3))
setProp("first_o", prop("name").trim().replace("o", "0"))
setProp("repeated", "~=".repeat(3))
```

Input fields: `name: text`, `code: number`, `csv: text`.

Input rows:

```json
[
  {"name":"  Notion  ","code":42,"csv":"apple,pear,orange"},
  {"name":"hi","code":7,"csv":"a"}
]
```

Output rows:

```json
[
  {"name":"  Notion  ","code":42,"csv":"apple,pear,orange","trimmed":"Notion","lowered":"  notion  ","padded":"00042","padded_text":"Notion..","pad_len":"11Notion","digits_removed":"Notion ","matches":["123","456"],"starts_blank":true,"label":"42-NOTION","parts":["apple","pear","orange"],"joined":"orange | pear | apple","first_part":"apple","has_pear":true,"len":10,"sub":"Not","first_o":"N0tion","repeated":"~=~=~="},
  {"name":"hi","code":7,"csv":"a","trimmed":"hi","lowered":"hi","padded":"00007","padded_text":"hi......","pad_len":"111111hi","digits_removed":"hi ","matches":["123","456"],"starts_blank":false,"label":"7-HI","parts":["a"],"joined":"a","first_part":"a","has_pear":false,"len":2,"sub":"hi","first_o":"hi","repeated":"~=~=~="}
]
```

Exceptions raised:

```json
[]
```

Final context:

```json
{}
```

### view-compare-fields

```text
setRowStyle("background", "gray")

if(
  prop("NAV") < prop("Commitment"),
  do(
    setStyle("Fund name", "text_color", "rose"),
    setRowStyle("background", "rose")
  )
)
```

View formula. Fields: `Fund name: text`, `NAV: number`, `Commitment: number`.

Rows:

```json
[
  {"Fund name":"Alpha","NAV":80,"Commitment":100},
  {"Fund name":"Beta","NAV":120,"Commitment":100},
  {"Fund name":"Gamma","NAV":null,"Commitment":100}
]
```

Styles and display text per row:

```json
[
  {"cells":{"Fund name":{"text_color":"rose"}},"row":{"background":"rose"},"display":{}},
  {"cells":{},"row":{"background":"gray"},"display":{}},
  {"error":"Numeric operand is empty"}
]
```

### view-display-setprop

```text
if(
  prop("Expiry") < now(),
  setProp("Fund ID", concat(prop("Fund ID"), " <- EXPIRED!"))
)

if(test(prop("Fund ID"), "EXPIRED!$"), setStyle("Fund ID", "strikethrough", true))

setProp("Amount", if(empty(prop("Amount")), "N/A", format(prop("Amount"))))
```

View formula. Fields: `Fund ID: text`, `Expiry: date`, `Amount: number`.

Clock: `now()` is `2026-10-29T00:00:00Z`.

Rows:

```json
[
  {"Fund ID":"F-14","Expiry":"2026-01-31","Amount":1500},
  {"Fund ID":"F-15","Expiry":"2027-06-30","Amount":null}
]
```

Styles and display text per row:

```json
[
  {"cells":{"Fund ID":{"strikethrough":true}},"row":{},"display":{"Fund ID":"F-14 <- EXPIRED!","Amount":"1500"}},
  {"cells":{},"row":{},"display":{"Amount":"N/A"}}
]
```

### view-fund-id-suffix

```text
if(test(prop("Fund ID"), "14$"), setStyle("Fund ID", "background", "lime"))
```

View formula. Fields: `Fund ID: text`.

Rows:

```json
[
  {"Fund ID":"F-2014"},
  {"Fund ID":"F-2015"},
  {"Fund ID":null}
]
```

Styles and display text per row:

```json
[
  {"cells":{"Fund ID":{"background":"lime"}},"row":{},"display":{}},
  {"cells":{},"row":{},"display":{}},
  {"cells":{},"row":{},"display":{}}
]
```

### view-me

```text
if(
  prop("Assignee").includes(me()),
  setRowStyle("background", "sky").setRowStyle("bold", true)
)
```

View formula. Fields: `Assignee: list<text>`.

Viewer: `Ada Lovelace`.

Rows:

```json
[
  {"Assignee":["Ada Lovelace","Grace Hopper"]},
  {"Assignee":["Grace Hopper"]}
]
```

Styles and display text per row:

```json
[
  {"cells":{},"row":{"background":"sky","bold":true},"display":{}},
  {"cells":{},"row":{},"display":{}}
]
```

### view-option-color

```text
setStyle("Status", "dot", optionColor("Status"))

setStyle("Tags", "background", optionColor("Tags"))
```

View formula. Fields: `Status: text`, `Tags: list<text>`.

Option colours:

```json
{"Status":{"Open":"green","Closed":"gray"},"Tags":{"urgent":"red","fx":"sky"}}
```

Rows:

```json
[
  {"Status":"Open","Tags":["ops","urgent","fx"]},
  {"Status":"Draft","Tags":[]},
  {"Status":null,"Tags":null}
]
```

Styles and display text per row:

```json
[
  {"cells":{"Status":{"dot":"green"},"Tags":{"background":"red"}},"row":{},"display":{}},
  {"cells":{},"row":{},"display":{}},
  {"cells":{},"row":{},"display":{}}
]
```

### view-reporting-gp-chain

```text
if(
  prop("Reporting GP").contains("Partners"),
  setStyle("Reporting GP", "icon", "thumbsup")
    .setStyle("Reporting GP", "text_color", "indigo")
)
```

View formula. Fields: `Reporting GP: text`.

Icons: `thumbsup`.

Rows:

```json
[
  {"Reporting GP":"Horizon Partners"},
  {"Reporting GP":"Acme Capital"}
]
```

Styles and display text per row:

```json
[
  {"cells":{"Reporting GP":{"icon":"thumbsup","text_color":"indigo"}},"row":{},"display":{}},
  {"cells":{},"row":{},"display":{}}
]
```
