Formula reference¶
Every SQL expression family the Formula, Multi-Field Formula and Filter nodes support, with working examples. For how to open the editor and add formula cards, see Formula. For the broader language rules, see SQL expressions.
New to formulas?
Start with Formula for a guided walkthrough, then use this page as a function lookup.
Column references¶
Put a column name in square brackets: [Invoice Amount]. Spaces in names are fine. Case is ignored and spaces just inside the brackets are trimmed, so [invoice amount] and [ Invoice Amount ] both resolve to Invoice Amount.
Unknown names are not columns: the engine reports Referenced column "x" not found.
Expression families¶
Standard operators. When a column comes from a CSV file it arrives as text; use TRY_CAST before doing maths on it.
| Expression | Result |
|---|---|
[price] + [tax] |
Sum |
[amount] - [discount] |
Difference |
[price] * [quantity] |
Product |
[total] / [count] |
Quotient |
[total] % [divisor] |
Remainder |
[total] // [divisor] |
Integer (floor) division |
Examples:
Text columns
[order_value] + 1 fails when the column is text. Wrap it first: TRY_CAST([order_value] AS DOUBLE) + 1.
CASE WHEN … THEN … ELSE … END and the shorthand IF.
CASE
WHEN [department] = 'Sales' AND [salary] > 75000 THEN 'Senior Sales'
WHEN [department] = 'Engineering' AND [salary] > 90000 THEN 'Senior Engineer'
ELSE 'Standard'
END
Multi-section pattern: use an earlier section's output in a later one.
| Function | What it does | Example |
|---|---|---|
UPPER(x) |
Upper case | UPPER([city]) → LONDON |
LOWER(x) |
Lower case | LOWER([name]) → acme ltd |
TRIM(x) |
Remove leading/trailing spaces | TRIM([name]) |
LTRIM(x) / RTRIM(x) |
Trim one side only | |
LENGTH(x) |
Character count | LENGTH([name]) |
LEFT(x, n) |
First n characters | LEFT([code], 3) |
RIGHT(x, n) |
Last n characters | RIGHT([ref], 4) |
SUBSTRING(x, start, len) |
Extract a slice | SUBSTRING([code], 1, 3) |
LPAD(x, n, pad) |
Pad on the left | LPAD([id], 6, '0') → 000042 |
RPAD(x, n, pad) |
Pad on the right | |
REPLACE(x, from, to) |
Replace all occurrences | REPLACE([name], '-', ' ') |
SPLIT_PART(x, delim, n) |
n-th token after splitting | SPLIT_PART([email], '@', 2) |
CONCAT(a, b, …) |
Join strings | CONCAT('INV-', [id]) |
a \|\| b |
Join strings (operator form) | [first] \|\| ' ' \|\| [last] |
CONTAINS(x, sub) |
true if substring present | CONTAINS([note], 'urgent') |
STARTS_WITH(x, prefix) |
true if starts with | STARTS_WITH([code], 'A') |
| Function | What it does |
|---|---|
ROUND(x, n) |
Round to n decimal places |
ABS(x) |
Absolute value |
CEIL(x) |
Round up to next integer |
FLOOR(x) |
Round down to next integer |
POWER(x, n) |
x to the power n |
SQRT(x) |
Square root |
MOD(x, y) |
Remainder of x ÷ y |
GREATEST(a, b, …) |
Largest of the values |
LEAST(a, b, …) |
Smallest of the values |
LOG(x) / LOG(base, x) |
Natural or base logarithm |
EXP(x) |
e raised to x |
SIGN(x) |
−1, 0 or 1 |
Extracting parts:
| Expression | Returns |
|---|---|
YEAR([date_col]) |
Year as integer |
MONTH([date_col]) |
Month 1–12 |
DAY([date_col]) |
Day 1–31 |
HOUR([ts_col]) |
Hour 0–23 |
MINUTE([ts_col]) |
Minute 0–59 |
DAYOFWEEK([date_col]) |
0 (Sun) – 6 (Sat) |
DAYNAME([date_col]) |
'Monday' etc. |
QUARTER([date_col]) |
Quarter 1–4 |
EXTRACT(YEAR FROM [date_col]) |
Year (alternative form) |
DATE_PART('month', [date_col]) |
Month (alternative form) |
Formatting:
Truncating:
DATE_TRUNC('month', [ts_col]) -- first instant of the month
DATE_TRUNC('year', [date_col]) -- 1 Jan of the year
Differences:
DATEDIFF('day', [start_date], [end_date])
DATEDIFF('month', [start_date], [end_date])
DATEDIFF('year', [start_date], [end_date])
Current values:
Parsing text into a date (when the column is text):
TRY_CAST([date_text] AS DATE) -- ISO format: 2024-01-31
STRPTIME([date_text], '%d/%m/%Y')::DATE -- non-ISO: 31/01/2024
Always cast text first
A column from a CSV is text even when it looks like 2024-01-31. Use TRY_CAST([col] AS DATE) before calling date functions.
| Expression | What it does |
|---|---|
COALESCE(a, b, …) |
First non-null value in the list |
NULLIF(x, val) |
Returns null when x equals val, otherwise x |
IFNULL(x, default) |
Returns default when x is null |
x IS NULL |
True when x is null |
x IS NOT NULL |
True when x is not null |
| Expression | Converts to |
|---|---|
CAST([col] AS DOUBLE) |
Decimal number; fails on bad values |
TRY_CAST([col] AS DOUBLE) |
Decimal number; returns null on bad values |
CAST([col] AS INTEGER) |
Whole number |
TRY_CAST([col] AS INTEGER) |
Whole number, null on failure |
CAST([col] AS DATE) |
Date |
TRY_CAST([col] AS DATE) |
Date, null on failure |
CAST([col] AS TIMESTAMP) |
Date and time |
CAST([col] AS BOOLEAN) |
True / false |
CAST([col] AS VARCHAR) |
Text |
[col]::DATE |
Shorthand cast (DuckDB) |
Common type names:
| You mean | Use |
|---|---|
| Decimal / float | DOUBLE or FLOAT |
| Whole number | INTEGER or BIGINT |
| Text / string | VARCHAR |
| Date | DATE |
| Date and time | TIMESTAMP |
| Yes / no | BOOLEAN |
Prefer TRY_CAST
Use TRY_CAST whenever the data might be messy. Plain CAST stops the node at the first bad value; TRY_CAST returns an empty cell instead, so the run continues.
| Operator | Meaning |
|---|---|
= |
Equal |
<> or != |
Not equal |
<, >, <=, >= |
Less / greater than |
x BETWEEN a AND b |
Inclusive range |
x IN ('a', 'b', 'c') |
Member of list |
x NOT IN (…) |
Not in list |
x LIKE 'A%' |
Pattern match (case-sensitive) |
x ILIKE '%acme%' |
Pattern match (case-insensitive) |
x NOT LIKE '%test%' |
Inverse pattern |
AND, OR, NOT |
Logical operators |
x IS NULL |
Null check |
Comparing text with numbers
[order_value] > 200 fails when the column is text. Cast first: TRY_CAST([order_value] AS DOUBLE) > 200.
| Function | What it does |
|---|---|
REGEXP_MATCHES(x, pattern) |
True when the full string matches |
REGEXP_REPLACE(x, pattern, replacement) |
Replace all matches |
REGEXP_REPLACE(x, pattern, repl, 'g') |
Replace globally |
REGEXP_EXTRACT(x, pattern) |
First match of the full pattern |
REGEXP_EXTRACT(x, pattern, group) |
Capture group n |
REGEXP_EXTRACT_ALL(x, pattern) |
All matches as a list |
Patterns use standard regular-expression syntax.
Backslashes in patterns
In a DuckDB expression, write \\d to match a digit (the first \ escapes the second for SQL). Inside the formula editor this looks like '\\d+'.
A single Formula node can hold up to 5 sections, running top to bottom. Each section can reference columns created by earlier sections in the same node.
Pattern: parse then extract
-- Section 1: target "audit_date"
TRY_CAST([audit_date_text] AS DATE)
-- Section 2: target "audit_year" (uses audit_date)
YEAR([audit_date])
-- Section 3: target "audit_month" (uses audit_date)
MONTH([audit_date])
Pattern: clean then categorise
-- Section 1: target "amount_num"
TRY_CAST(REPLACE([amount], ',', '') AS DOUBLE)
-- Section 2: target "size_band" (uses amount_num)
CASE
WHEN [amount_num] >= 10000 THEN 'Large'
WHEN [amount_num] >= 1000 THEN 'Medium'
WHEN [amount_num] IS NULL THEN 'Unreadable'
ELSE 'Small'
END
Pattern: build an identifier
Common pitfalls¶
CAST on a bad value stops the whole node
Fix: useTRY_CAST so bad values become empty instead:
Adding text with +
Fix: use|| or CONCAT:
Using = to check for null
Fix: useIS NULL:
Preview uses 100 rows
The editor evaluates your formula on the first 100 rows of preview data. A bad value that sits on row 10,000 will not appear until you Run. Use TRY_CAST to guard against late surprises.
Back to the Formula node · Preparation node index