Skip to content

Let

Logic & variables

Let(name, expr, body)

Binds name to expr for use inside body — for readability and efficiency: the bound expression is computed once in the compiled SQL even if referenced repeatedly. Nest Lets for multiple bindings: Let(a, …, Let(b, …, body)). The SquareX equivalent of DAX VAR … RETURN.

  • A sub-expression used two or more times — margin numerators, shared denominators.
  • Making a dense ratio readable: name the parts, then state the formula.
MarginPct := Let(rev, [Revenue],
Divide(rev - Sum(Sales.Cost), rev))
  • A binding named after a function is an error (SQX013); shadowing an outer Let binding is only a warning (SQXW01).
  • Measures using Let open as code in the editor — the template builder shows a read-only summary.