Skip to main content
Formula table calculations let you write table calculations in a spreadsheet-style syntax, the way you would in Google Sheets or Excel, instead of raw SQL. When you create a new table calculation, Formula is the default input mode. You can switch to the SQL editor any time.
Creating a formula table calculation

Why use formulas?

  • Faster to write for common calculations. No OVER (…) or CASE WHEN boilerplate 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.
If you need something the formula syntax doesn’t cover yet, the SQL editor is always one click away.

Supported warehouses

Formula table calculations work on every warehouse Lightdash supports: Athena, BigQuery, ClickHouse, Databricks, DuckDB, PostgreSQL, Redshift, Snowflake, and Trino. The same formula compiles to the correct SQL for whichever warehouse your project is connected to.

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):
The result appears as a new green column in your results table:
Formula table calculation in the results table
You can use:
  • 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

Logical

String

Date

unit is always one of "day", "week", "month", "quarter", "year" β€” quoted as a string literal.

Aggregation

Window

Null handling

Examples

Gross margin as a percentage
Flag high-value orders
Running total of revenue
Period-over-period growth %
Bucket customers by spend
Percent of total

FAQ

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.
Post in the Lightdash Community Slack or open a GitHub issue. See Contact Us for more options.