Sub topic 1
Tour of the Power Query Editor
Prerequisites
This chapter assumes you can open Power BI Desktop and connect to a simple source such as a CSV or Excel file. It also assumes you know what tables, rows, columns, and data types are. You don't need to know any M code yet.
What the editor is
The Power Query Editor is a separate window inside Power BI Desktop. You use it to shape data before it reaches the model. Each change you make is saved as a step in a query, and Power BI replays those steps every time the data refreshes.
To open it, select Home > Transform data. If you pick Load instead, the data goes straight to the model with no cleaning.
The main areas
| Area | Location | What it does |
|---|---|---|
| Ribbon | Top | Holds the Home, Transform, Add Column, and View tabs. Most cleaning commands live here. |
| Queries pane | Left | Lists every query in the file. Select one to work on it. |
| Data preview | Center | Shows the result of the selected step, not necessarily the final result. |
| Formula bar | Above the preview | Shows the M expression for the selected step. |
| Query Settings pane | Right | Holds the query name and the Applied Steps list. |
The status bar at the bottom shows the column count and row count. It also tells you when the preview is based on a sample of the data.
How the pieces work together
Selecting a step in Applied Steps changes what the preview and formula bar show. The preview shows the table as it looked right after that step. This lets you check each step on its own.
Here is the code behind a tiny two-step query. You can see the same code in Home > Advanced Editor.
let
Source = #table({"Product", "Amount"}, {{"Widget", 10}, {"Gadget", 4}}),
Sorted = Table.Sort(Source, {{"Amount", Order.Descending}})
in
SortedThe Applied Steps list would show Source and Sorted. Selecting Sorted puts the Table.Sort(...) call in the formula bar. The next chapter covers this code in more detail.
Common errors
- Editing an earlier step by accident. If you select a step in the middle of the list and add a transformation, the editor asks whether to insert the step there. Inserting can break later steps that depend on the old column names or types. Select the last step before you add new work.
- Trusting the preview as the whole table. The preview and column profiling can be based on only the first 1,000 rows. A problem lower in the data may not show up yet.
- Closing without applying. Changes in the editor do not reach the report until you select Close & Apply. Until then, your visuals still use the old data.
- Renaming a step's column in a later step only. Steps refer to columns by name. If a source column is renamed, earlier steps fail with an error.
Exercise
You select the third step in Applied Steps and the data preview changes. What does the preview now show, and where can you see the code for that step?
Show answer
The preview shows the table as it was right after the third step ran. The code for that step appears in the formula bar. If the bar is hidden, turn it on with View > Formula Bar.
Exercise
You added a transformation to a query, but your report visuals still show the old data. What did you most likely forget to do?
Show answer
You did not select Close & Apply. Changes in the Power Query Editor reach the model only after you apply them.