Formula table calculations are in Beta (Early Access).The feature is enabled by default on supported warehouses, with no
flag required, and we’re actively expanding the function catalog.
We’d love your feedback while we iterate. See feature maturity levels
for details.

Why use formulas?
- Faster to write for common calculations. No
OVER (…)orCASE WHENboilerplate to remember. - Familiar if you’ve used Google Sheets, Excel, or Airtable.
- Portable across warehouses. The same formula compiles to the correct SQL for whichever warehouse your project is connected to.
Supported warehouses
| Warehouse | Formula support |
|---|---|
| BigQuery | ✅ |
| ClickHouse | ✅ |
| Databricks | ✅ |
| DuckDB | ✅ |
| PostgreSQL | ✅ |
| Redshift | ✅ |
| Snowflake | ✅ |
| Athena | 🚧 Not yet |
| Trino | 🚧 Not yet |
Writing your first formula
Every formula starts with=. Reference a field by its column name
(the same name you see in the results table header):

- Numbers:
42,3.14,-1.5 - Strings:
"hello"or'hello' - Booleans:
TRUE,FALSE - Column references: any field present in your results table
- Arithmetic operators:
+,-,*,/,%(modulo) - Comparison operators:
=,<>,>,<,>=,<= - Boolean operators:
AND,OR,NOT
Function reference
Math
| Function | Description |
|---|---|
ABS(x) | Absolute value |
ROUND(x, [digits]) | Round to N decimal places |
CEIL(x) / CEILING(x) | Round up to nearest integer |
FLOOR(x) | Round down to nearest integer |
MIN(x, [y]) | Minimum (scalar or aggregate) |
MAX(x, [y]) | Maximum (scalar or aggregate) |
Logical
| Function | Description |
|---|---|
IF(condition, then, [else]) | Conditional expression |
AND, OR, NOT | Boolean operators |
=, <>, >, <, >=, <= | Comparison operators |
String
| Function | Description |
|---|---|
CONCAT(a, b, …) | Concatenate strings |
LEN(s) / LENGTH(s) | String length |
TRIM(s) | Remove whitespace |
LOWER(s) | Convert to lowercase |
UPPER(s) | Convert to uppercase |
Date
| Function | Description |
|---|---|
TODAY() | Current date |
NOW() | Current timestamp |
YEAR(d) | Extract year |
MONTH(d) | Extract month |
DAY(d) | Extract day |
Aggregation
| Function | Description |
|---|---|
SUM(x) | Sum values |
AVG(x) / AVERAGE(x) | Average values |
COUNT([x]) | Count rows (or non-null x) |
SUMIF(condition, x) | Sum where condition is true |
AVERAGEIF(condition, x) | Avg where condition is true |
COUNTIF(condition) | Count where condition true |
Window
| Function | Description |
|---|---|
RUNNING_TOTAL(x) | Running (cumulative) total |
ROW_NUMBER() | Sequential row number |
RANK() | Rank with gaps |
DENSE_RANK() | Rank without gaps |
LAG(x, [offset], [default]) | Previous row’s value |
LEAD(x, [offset], [default]) | Next row’s value |
FIRST(x) | First value in window |
LAST(x) | Last value in window |
NTILE(n) | Distribute rows into N buckets |
MOVING_SUM(x, n) | Sum of the last N rows |
MOVING_AVG(x, n) | Average of the last N rows |
Null handling
| Function | Description |
|---|---|
COALESCE(a, b, …) | First non-null argument |
ISNULL(x) | TRUE if x is null |
Examples
Gross margin as a percentageFAQ
Can I switch between SQL and Formula on the same table calculation?
Can I switch between SQL and Formula on the same table calculation?
No. The input mode is chosen when you create the table calculation
and can’t be changed afterwards, because formulas and SQL aren’t
always losslessly interconvertible. If you need to move a SQL calc to
a formula (or vice versa), delete the old one and create a new one in
the mode you want.
What happens if my warehouse isn't supported yet?
What happens if my warehouse isn't supported yet?
The Formula toggle is hidden and the SQL editor is the only option.
Existing SQL table calculations keep working on every warehouse. The
beta is strictly additive.
I found a bug or want a function that isn't listed
I found a bug or want a function that isn't listed
Post in the Lightdash Community Slack
or open a GitHub issue.
See Contact Us for more options.

