-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

The Definitive Guide to Power Query (M)
By :

As previously noted, M is a powerful language designed for data ingest and transformation within a variety of Microsoft software and services. Understanding the basics of the M language is essential for effectively leveraging its capabilities.
Here are some important fundamentals regarding the M language:
Text.Start("Hello, World!", 5)
returns the substring Hello
from the input text. More about expressions and functions are covered in Chapter 4, Understanding Values and Expressions, as well as Chapter 9, Parameters and Custom Functions.Text.From
function converts a value to text, while the Date.Year
function extracts the year component from a date or datetime value. Data types are covered in Chapter 5, Understanding Data Types.+
, -
, *
, /
, and so on) are used for numeric calculations, while comparison operators (>
, <
, =
, and so on) evaluate logical conditions. The combination operator ‘&
' is used for concatenating text values, appending lists and tables, or merging records. Operators are covered in Chapter 4, Understanding Values and Expressions.try
, otherwise
, and error
, you can control the flow of execution and handle potential errors gracefully. Additionally, M supports debugging capabilities, such as the ability to step through the code to identify and resolve issues in complex transformations. Error handling and debugging are covered in Chapter 12, Handling Errors and Debugging.//
) while block comments use the slash-asterisk/asterisk-slash pattern ( /*
and */
).Now that we have a good understanding of the core components of the M language, let’s next explore the most fundamental component of the M language, the let
expression.
At the core of the M language is the let
expression, which must be paired with an in
expression. In simple terms, the let
expression contains the input and transformations, while the in
expression contains the output. A simple Hello World
for M looks like the following:
let
Hello = "Hello World"
in
Hello
This code would return the ubiquitous Hello World
text.
It is important to note that every expression within a let statement must be followed by a comma ( ,
) except the last expression prior to the in
expression. Thus, if the let
expression consists of multiple sub-expressions, then the code might look like the following:
let
Hello = "Hello",
World = "World",
Return = Hello & " " & World
in
Return
This code also returns Hello World
as output.
Understanding the basics of M, including expressions, functions, data types, variables, operators, and the step-by-step transformation process, is vital for effectively manipulating and preparing data. By mastering these foundational concepts, you gain the ability to perform complex transformations, optimize data workflows, and unlock the full potential of the M language. The rest of this book is devoted to helping you master all of these foundational concepts and how to apply them to complex data transformations.