M let and in
Read a query as a dependency graph
A query is an expression that produces a value. The let part binds names to expressions and in selects the result. M is case-sensitive. Use commas between bindings and no comma immediately before in. Names containing spaces can be written as quoted identifiers, for example #"Line total". A quoted identifier refers to a name, while "Line total" is a text value. // starts a line comment; /* ... */ encloses a block comment. Bindings name values, not mutable variables. All examples are complete standalone expressions for a blank Power Query query in a disposable Desktop file unless marked otherwise. No account, connector, file or network is required. Expected results are derived, not observed; native M execution and exact Desktop build are NOT RUN.
Compute a line amount
let Units = 3, UnitPrice = 12, #"Line total" = Units * UnitPricein #"Line total"Expected: 36. The output depends on both numeric inputs; changing Units in the source expression creates a new evaluation, not a mutation of the old value. * multiplies; + adds; parentheses explicitly group arithmetic. For example (3 + 2) * 12 is 60, not 27.
Trace a dependency, not a sequence
let Total = Qty * Price, Qty = 2, Price = 15, Unused = error "Not requested"in TotalExpected: 30. Total may refer to bindings written below it. Qty and Price must be available to compute Total; the unused binding does not need evaluation. If in Unused replaces the final expression, the result is an error instead. Lazy evaluation means some expressions are evaluated only when needed; it does not promise a fixed physical evaluation order, caching across refreshes or a single enumeration of a streaming table.
Avoid procedural assumptions
Changing the order of independent bindings is not a way to force a side effect. Self-reference or a dependency cycle can fail. In Desktop, Applied Steps are named expressions, usually chained by dependency; the preview may request intermediate results. A section document is a separate language-level organization form: section Retail; shared TaxRate = 0.1; declares a named section and a shared member. It is not a standalone blank-query expression to paste into Advanced Editor. Sections may refer to qualified members such as Retail!TaxRate; ordinary query authoring here uses let instead.
Practice — Predict the results
Given let Gross = Units * 8, Units = 4, Fee = 2 in Gross - Fee, draw the dependency edges and predict the value. Then replace in Gross - Fee with in "Gross" and explain the different result. Identify which bindings the second expression needs.
Official reading
let · evaluation · operators · sections · Native execution NOT RUN. · lexical