Shape · Rows

Switch

Sends each row down one of several outputs: it goes to the first case whose condition is true, and rows that match none go to Default.

Also known as: Case when, if/else, conditional split

How it works

Cases is an ordered list; each case has a label and one condition written the way a Filter condition is, with a Value, Column or Expression on the right. A row is tested against the cases top to bottom and leaves through the first one whose condition is true; a condition that evaluates to NULL is no match. Rows matching no case leave through Default. Every case is its own output port, so you wire each branch separately; renaming or reordering a case keeps its wires, removing it removes them.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • default — Table

Settings

The Attributes panel of Switch, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  cases: [{ id?: string, label: string, condition: { column, operator: "="|"!="|">"|"<"|">="|"<="|"contains"|"is null"|"is not null"|"is empty"|"is not empty", value, rhsKind?: "value"|"column"|"expression", rhsColumn?, rhsExpression? } }]
}

cases are tried in order and a row goes to the FIRST whose condition is true (a NULL result is no match); rows matching no case go to the "default" output. Each case is its own output port (wire downstream nodes to it) — when editing an existing Switch keep each case's id, which is what its wires are attached to; omit id for a new case; the condition is a Filter condition — rhsKind "expression" = a raw boolean SQL fragment used as the whole predicate, e.g. "amount >= 1000 AND region = 'EU'"

Example

Size bands on amount, in this order so the widest test comes first:

CaseConditionGoes to
Largeamount ≥ 1000Large
Mediumamount ≥ 100Medium
(no match)Default, the small orders