Set up easy debugging and improve M code adoption …


Make M code adoption and debugging easy with record-expressions. In the M language, both let- and record-expressions are used to create more complex expressions. Let’s review them.

 

A let-expression starts with a let-clause and contains a comma-separated list of variables and expressions assigned to them. Variables can refer to other variables, and whatever is returned after the in-clause that’s the result of the let-expression.

 

To illustrate, this let-expression returns the value 6.

m_dekorte_0-1683459867434.png

 

A record-expression is a comma-separated list of fields, each field is a name/value pair. Fields can refer to other fields, and the result can be an entire record, a selection of fields, or a single field value.

 

To illustrate, this record-expression returns 6, like the let-expression above.

m_dekorte_1-1683459867437.png

 

 

Both let- and record-expressions require variable/field names to be unique. A key difference is that most of the time record-expressions allow field names to be written without the quoted notation, which improves the readability of the code.

 

The flexibility of a record-expression is what makes it truly valuable for adoption, validation, troubleshooting, debugging, and reviewing M code since you can quickly change its return value, as illustrated here:

 

Illustrating the flexibility of a record-expressionIllustrating the flexibility of a record-expression

 

The flexibility of record-expressions is what makes it valuable for adoption and troubleshooting. Key points to keep in mind:

Omit field selection: [b] 👉 to return the entire record.

Replace it with projection and selection: [[b], [c]] 👉 to return a record with selected fields.

 

Learn more about the let and record here, in the M language specification.

https://learn.microsoft.com/en-us/powerquery-m/m-spec-let

https://learn.microsoft.com/en-us/powerquery-m/m-spec-values#record



Source link

Be the first to comment

Leave a Reply

Your email address will not be published.


*