Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Power BI Quick Start Guide

You're reading from   Microsoft Power BI Quick Start Guide Bring your data to life through data modeling, visualization, digital storytelling, and more

Arrow left icon
Product type Paperback
Published in Oct 2020
Publisher Packt
ISBN-13 9781800561571
Length 296 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Bradley Schacht Bradley Schacht
Author Profile Icon Bradley Schacht
Bradley Schacht
Devin Knight Devin Knight
Author Profile Icon Devin Knight
Devin Knight
Erin Ostrowsky Erin Ostrowsky
Author Profile Icon Erin Ostrowsky
Erin Ostrowsky
Mitchell Pearson Mitchell Pearson
Author Profile Icon Mitchell Pearson
Mitchell Pearson
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with Importing Data Options 2. Data Transformation Strategies FREE CHAPTER 3. Building the Data Model 4. Leveraging DAX 5. Visualizing Data 6. Digital Storytelling with Power BI 7. Using a Cloud Deployment with the Power BI Service 8. Data Cleansing in the Cloud with Dataflows 9. On-Premises Solutions with Power BI Report Server 10. Other Books You May Enjoy
11. Index

The M formula language

The Power Query Editor is the user interface that 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 language's 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 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. On the Home ribbon, select Advanced Editor to see the M query that has been written by the user interface. Figure 2.27 shows an example of what your Advanced Editor might show:

Figure 2.27: Understanding the elements of M

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

  1. The 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". If a space is not required in the name of your step then the double quotes are not required.
  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. The in expression: Oddly, the in expression is actually a reference to what the query will output. Whichever named 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."

#shared

As mentioned previously, this book will not dive deep into writing your own M queries since that would be far beyond the essentials of Power BI. However, there is a great method for exploring the M functions that are available, and how to use them. Within the Power Query Editor, you can use the #shared function to return documentation on every available function in the M library. Let's walk through how you can leverage this tool:

  1. In a new instance of Power BI Desktop, select Get data and then choose Blank Query. This will launch the Power Query Editor with an empty formula bar waiting for you to provide your own M.
  2. In this formula bar, type = #shared, then hit Enter. Remember that M is case-sensitive so you must use a lowercase s when typing shared.
  3. This will return a list of all the available M functions. By selecting the cell that has the hyperlink text of a certain function, you can see documentation on how to use each function. Figure 2.28 shows an example of this:

Figure 2.28: Example of function documentation

This is a great method for learning what M functions are available, and how each may be used. If you are stumped on how to solve a problem using M then make this your first stop to explore what options you have.

You have been reading a chapter from
Microsoft Power BI Quick Start Guide - Second Edition
Published in: Oct 2020
Publisher: Packt
ISBN-13: 9781800561571
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime