Home Tutorials Power BI Tutorial Power Query M basics
Power Query M basics

Power Query M basics


The M Language (Power Query Formula Language)

Description: M is the powerful functional language that drives Power Query. Every time you click a button in the Power Query interface—such as "Remove Columns" or "Filter Rows"—Power BI writes a line of M code behind the scenes to execute that command. It is a "step-based" language designed specifically for data transformation and mashup.

Why: While the user interface covers 90% of common tasks, understanding that M exists is a key step in moving from a beginner to an intermediate user. It allows you to troubleshoot complex data imports and understand exactly how Power BI is manipulating your raw files before they enter the data model.


The "Advanced Editor"

To see the M code for your current project, you can open the Advanced Editor window from the "View" or "Home" tab in Power Query. Here, you will see a series of let and in statements that define your data cleaning workflow.

Syntax Example:

= Table.RemoveColumns(Source, {"UnwantedColumn"})

In this snippet, Table.RemoveColumns is the function, Source is the name of the previous step, and "UnwantedColumn" is the specific data to be deleted.

The Structure of M

  • The "Let" Block: This is where the variables and transformation steps are defined. Each step usually refers to the step immediately preceding it.
  • The "In" Block: This is the final output. It tells Power Query which step represents the finished, "clean" table to be loaded into Power BI.
  • Case Sensitivity: Unlike some other languages, M is strictly case-sensitive. A function like Table.SelectRows will fail if written as table.selectrows.

Key Notes

  • No Need to Memorize: Beginners do not need to learn how to write M code from scratch. The graphical interface is designed so you can perform nearly all cleaning tasks using buttons and menus.
  • Formula Bar: You can see the M code for any single step by looking at the Formula Bar located just above the data preview in Power Query. This is a great way to start learning the syntax piece by piece.
  • Custom Functions: Advanced users use M to create custom functions that can perform the same cleaning steps on hundreds of different files simultaneously, greatly increasing efficiency.

🏋️ Test Yourself With Exercises

Take our quiz on Power Query M basics to test your knowledge.

Browse Quizzes »