Let Expression

Free Preview

Exercise file name:

4 M expressions.pbix

Content from the official Reference guide

The let expression allows a set of values to be computed, assigned names, and then used in a subsequent expression that follows the in. For example, in our sales data example, we could do:

Sales2007 =
Year = 2007,
FirstHalf = 1000,
SecondHalf = 1100,
Total = FirstHalf + SecondHalf // 2100
Sales2008 =
Year = 2008,
FirstHalf = 1200,
SecondHalf = 1300,
Total = FirstHalf + SecondHalf // 2500
in Sales2007[Total] + Sales2008[Total] // 4600

The result of the above expression is a number value (4600) which was computed from the values bound to the names Sales2007 and Sales2008.

Was this helpful?
Lesson tags: M language, Power Query
Back to: M Language Online Course: The unofficial and Practical Reference Guide > M Expressions

Reader Interactions


  1. You should mention that the last part, how M computes without regard to the order of statements, is why it is called a functional language. The items between “let” and “in” are not presented in procedural order, they are just defining relationships among variables, and as such the relationships are constant (immutable) and do not depend on the order of execution. Well, at least that is how I conceptualize it!

Leave a Reply to cvanhasselt Cancel reply