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:
letopens 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;
inindicates the step returned as the result;- M is case-sensitive:
Table.RowCountworks,table.rowcountdoesn’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.
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- Import this file with Get data > Text/CSV, then click Transform Data.
- Turn on the formula bar and the Column quality and Column profile options (View tab).
- Click each of the applied steps and watch the formula bar.
- Remove the
Categoriecolumn, then rename the step created toSansCategorie. - 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
Complete an M query
Complete the query so that it promotes the headers then types the columns
Date(date) andQuantite(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 ...Role of let ... in
In an M query, what does the expression placed after
indesignate?- The first step
- The result returned by the query
- The path of the source file
- A comment
End-of-lesson quiz
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
How do you write a step name containing spaces in M?
- #"Type modifié"
- [Type modifié]
- 'Type modifié'
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
- Cleaning Data: Types, Blanks, Duplicates, Text20 min
- Adding Columns: Custom, Conditional, Split15 min
- Combining Queries: Append and Merge20 min
- Reshaping (Unpivot, Group) and Best Practices20 min