Skip to content

Let

Let(name, expr, body) · Logic & variables

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.

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.