The Power Query Editor and the M Language

First lesson of the Power Query: Import and Transform course, free to read: about 15 minutes, 3 exercises and 3 quiz questions. This is the catalogue's base lesson; in the student space, it is rewritten for your profile.

Objectives

  • Open the Power Query editor and identify its areas
  • Read the list of applied steps and the formula bar
  • Understand the let ... in structure of an M query

Power Query editorApplied stepsM language

What Is Power Query?

Power Query is the data preparation engine built into Power BI (and Excel). It lets you import, clean and reshape data without writing code, then automatically replay all these operations at every refresh. Your source files are never modified: Power Query reads the source and applies its transformations on the fly.

You open it from Power BI Desktop with Home > Transform data.

The Areas of the Editor

  • The Queries pane (on the left): the list of queries; each one becomes a table in the model if loading is enabled.
  • The data preview (in the center): a few rows of the selected query. The icon to the left of each header shows the type (ABC for text, 123 for whole number, 1.2 for decimal, calendar for date).
  • The Query Settings (on the right): its name and above all the list of applied steps.
  • The ribbon: tabs Home, Transform, Add Column, View.
  • The formula bar: shows the code of the selected step. If it isn’t visible, turn it on in the View tab.

In the View tab, also turn on Column quality, Column distribution and Column profile: you immediately see the percentage of valid values, errors and blanks. By default, this profile covers the first 1,000 rows; you can extend it to the whole dataset in the status bar.

One Action = One Step

Each click creates a step. For example, removing a column adds the step Removed Columns. Clicking a step shows the data at that stage: an excellent way to debug. You can:

  • rename a step (right-click > Rename) to document your work;
  • delete a step (cross);
  • edit its parameters (gear icon).

Careful: steps are chained. Deleting or editing a step in the middle can break the following ones (for example if they use a column that has disappeared).

The M Language

Behind the interface, every query is a program in the M language. Open Home > Advanced Editor to see it in full:

let
    Source = Csv.Document(File.Contents("C:\Formation\ventes.csv"),
        [Delimiter = ",", Encoding = 65001, QuoteStyle = QuoteStyle.Csv]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",
        {{"Date", type date}, {"Quantite", Int64.Type}, {"PrixUnitaire", Int64.Type}})
in
    #"Changed Type"

Key points:

  • let opens the list of steps, separated by commas;
  • each step has a name; names with spaces or accents are written #"...";
  • each step generally uses the result of the previous one;
  • in indicates the step returned as the result;
  • M is case-sensitive: Table.RowCount works, table.rowcount doesn’t.

You don’t need to write M to use Power Query well, but being able to read it will let you understand and fix your queries.

Close & Apply

When your transformations are ready, Close & Apply loads the result into the model. Apply loads without closing the editor.

Exercises

Solutions and tests stay on the server. In the student space, your code is run and checked, and the tutor gives hints before the solution.

  1. TaskDifficulty 12 hints

    Explore a query

    In Notepad, create the file C:\Formation\ventes.csv (UTF-8 encoding):

    Date,Magasin,Categorie,Produit,Quantite,PrixUnitaire
    2026-01-03,Lyon,Boissons,Jus d'orange,10,3
    2026-01-03,Lille,Epicerie,Pates,20,2
    2026-01-10,Nantes,Frais,Yaourt,30,1
    2026-01-17,Lyon,Epicerie,Riz,15,2
    2026-01-24,Lille,Boissons,Eau,50,1
    2026-02-02,Nantes,Boissons,Jus d'orange,12,3
    2026-02-07,Lyon,Frais,Fromage,8,6
    2026-02-14,Lille,Frais,Yaourt,25,1
    2026-02-21,Nantes,Epicerie,Pates,18,2
    2026-02-28,Lyon,Boissons,Eau,40,1
    2026-03-06,Lille,Epicerie,Riz,10,2
    2026-03-13,Nantes,Frais,Fromage,5,6
    1. Import this file with Get data > Text/CSV, then click Transform Data.
    2. Turn on the formula bar and the Column quality and Column profile options (View tab).
    3. Click each of the applied steps and watch the formula bar.
    4. Remove the Categorie column, then rename the step created to SansCategorie.
    5. Open the advanced editor and find your step in the code.
    • The query has at least the steps Source, Promoted Headers, Changed Type and SansCategorie
    • Column quality shows 100% valid values for Quantite
    • The advanced editor shows the SansCategorie step using Table.RemoveColumns
  2. CodeDifficulty 22 hints

    Complete an M query

    Complete the query so that it promotes the headers then types the columns Date (date) and Quantite (whole number). The query must return the last step.

    let
        Source = Csv.Document(File.Contents("C:\Formation\ventes.csv"), [Delimiter = ",", Encoding = 65001]),
        // Étape 1 : promouvoir les en-têtes
        Entetes = ...,
        // Étape 2 : typer Date et Quantite
        Types = ...
    in
        ...
  3. Multiple choiceDifficulty 11 hint

    Role of let ... in

    In an M query, what does the expression placed after in designate?

    • The first step
    • The result returned by the query
    • The path of the source file
    • A comment

End-of-lesson quiz

  1. What happens to the source file when you delete a column in Power Query?

    • The column is deleted from the file
    • Nothing: the transformation only applies to the query result
    • The file is renamed
  2. How do you write a step name containing spaces in M?

    • #"Type modifié"
    • [Type modifié]
    • 'Type modifié'
  3. What does the Column quality option show?

    • The percentage of valid values, errors and blanks
    • The color of the column
    • The size of the file

The rest of the course

  1. Cleaning Data: Types, Blanks, Duplicates, Text20 min
  2. Adding Columns: Custom, Conditional, Split15 min
  3. Combining Queries: Append and Merge20 min
  4. Reshaping (Unpivot, Group) and Best Practices20 min

Power Query: Import and Transform · Beginner · 1 h 30 min