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.
When to use it
Section titled “When to use it”- A sub-expression used two or more times — margin numerators, shared denominators.
- Making a dense ratio readable: name the parts, then state the formula.
Example
Section titled “Example”MarginPct := Let(rev, [Revenue], Divide(rev - Sum(Sales.Cost), rev))Good to know
Section titled “Good to know”- A binding named after a function is an error (SQX013); shadowing an outer
Letbinding is only a warning (SQXW01). - Measures using
Letopen as code in the editor — the template builder shows a read-only summary.