Microsoft Power BI Complete Reference
上QQ阅读APP看书,第一时间看更新

M formula language

The Power Query Editor is the user interface that you have now learned is used to design and build data imports. However, you should also know that every transform you apply within this editor is actually, quietly and behind the scenes, writing an M query for you. The letter M here is a reference to the languages data mashup capabilities.

For simple solutions, it is unlikely that you will ever need to even look at the M query that is being written, but there are some more complex cases where it's helpful to understand how to read and write your own M. For the purposes of this book, covering just the Power BI essentials, you will learn how to find the M query editor within your solution and then understand how to read what it is doing for you. For the purposes of this example, you can open up any previously built example, however, the screenshot used here is coming from the very first example in this chapter on basic transforms.

  1. Using any Power BI solution you have designed, launch the Power Query Editor.
  2. Under the Home Ribbon, select Advanced Editor to see the M query that has been written by the user interface:

This query has been formatted to make it easier to read. Let's review the key elements that are present here:

  1. Let Expression: Encapsulates a set of values or named expressions to be computed.
  2. Named Expressions or Variables: The name given to a set of operations in a step. These names can be anything, but you should note that if you wish to have a space in the name of a step then it must be surrounded by #"". For example, If I wanted something to be called Step 1, then I would have to name an expression #"Step 1".
  3. M Functions: The operations that are used to manipulate the data source.
  4. Prior Step Reference: The M Query language generally executes its functions as serial operations, meaning each operation is executed one after the other sequentially. You can see this when you look at a query because each call to an M function always references the prior-named expression, to pick up where it left off.
  5. In Expression: Oddly, the In expression is actually a reference to what the query will output. Whichever name expression is referenced in the In expression will be what is returned back in the Power Query Editor preview.
It is important to realize that M is case-sensitive. That means if you ever make a change to a query or write one from scratch, you should be careful because there is a difference between "a" and "A".