If you use Power BI Desktop and Query Editor, do you know the true power of M? As you probably know, the Query Editor in Power BI is a powerful GUI that generates M, also known as the Power Query formula language. In a recent webinar, Pragmatic Works founder, Brian Knight, took a deep dive behind the GUI, so attendees could learn how to do even more data cleansing and transformation in Power BI using M.
What is M Query? M stands for Mashup—getting your data and mashing it together in very creative ways. M is easily made dynamic. For example, you can take a data set and set a dynamic date range.
The real reason to use M—Data Transformation. You can pivot/unpivot, remove unwanted characters and split columns. M is optimized for building highly flexible data mashup queries.
Some M Query fundamentals:
Where to write M:
You can write it in the Query Editor formula bar (much like in Excel) or you can use view>Advanced Editor.
M Query Result:
Can produce a single value, list (array), table (much like a list but can be formatted/filtered) or function (similar to what you can do with .net or T-SQL.)
M Query Tips:
A big thing to keep in mind is that M query is case sensitive, not as forgiving as T-SQL.
Using #shared to return library functions. This gives you the ability to see all the functions available to you and all the functions that have been used on a Power BI sheet.
Variables and Functions:
This is where we see the power of M come into play. A variable is a placeholder. It is changeable, not constant. But the real power of M comes in working with functions. Functions allow us to automate a whole bunch of processes with an M query, like split columns or make proper case. You can automate a function, for example: if looping over a folder of files, you can automate it to do a chosen function for every file that you pass through this function. This automation is truly what makes M so powerful.
Brian’s webinar is full of demos, including M Query basics, understanding M Query, taking a look at M code and variables and functions. So, check out Brian’s webinar to learn more and if you want an intensive course, our Power Query for Business is just what you need. Visit our website to learn more about this, and our other 30+ On-Demand Training courses.