Sub topic 14
Where Power Query Editor Fits
This chapter assumes you have installed Power BI Desktop, loaded a dataset with Get data, and moved between Report, Table, and Model views. It explains where Power Query Editor sits in that workflow, how it differs from the three views, and which errors learners hit most often when they mix the two up.
Two layers, not three views plus one
Report, Table, and Model views all work on the loaded data model. Power Query Editor works earlier, on the data on its way into the model. It opens in its own window, not as a fourth icon in the view switcher.
The distinction matters because the two layers change different things:
- Power Query Editor changes what gets loaded. You remove columns, filter rows, fix types, split text, and merge sources. Each step is recorded and replayed on every refresh.
- Table and Model views change how loaded data is described and connected. You set formats, sort orders, summarization, and relationships.
- Report view changes how the loaded data is displayed.
How you get into the editor
When you use Get data on a file such as a CSV or Excel workbook, a Navigator or preview window appears with two main buttons: Load and Transform Data. Load sends the data straight into the model with no changes. Transform Data opens Power Query Editor first, so you can adjust the data before it loads.
You can also open the editor at any time after loading:
- On the Home tab of the ribbon, select Transform data.
- Choose Transform data from the dropdown if a menu appears.
- The editor opens in a separate window over Power BI Desktop.
You can also right-click a table in the Data pane and choose Edit query.
A tour of the editor window
The editor has a different layout from the three main views. These are the parts you will use first:
| Area | Purpose |
|---|---|
| Queries pane (left) | Lists one query for each table you loaded. Each query becomes a table in the model. |
| Data preview (center) | Shows a sample of the rows for the selected query. |
| Ribbon (top) | Holds the Home, Transform, Add Column, and View tabs. |
| Query Settings pane (right) | Shows the query name and the Applied Steps list. |
| Formula bar | Shows the M code for the selected step. |
The Applied Steps list is the most important part. Every action you take adds a step, such as Source, Navigation, Promoted Headers, Changed Type, or Removed Columns. Selecting an earlier step shows the data as it looked at that point. Steps run top to bottom, so the order matters.
The M language behind the steps
Each step is a line of M, the Power Query formula language. You rarely need to write M by hand at this stage, but you should know it exists. To see the full script for a query, open the Advanced Editor from the Home tab.
let
Source = Csv.Document(File.Contents("C:\Data\sales.csv"), [Delimiter=",", Encoding=65001]),
PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
ChangedType = Table.TransformColumnTypes(PromotedHeaders, {{"SalesAmount", type number}})
in
ChangedTypeEach named line is one applied step, and each step takes the previous step's result as its input. The in clause names the step whose result becomes the table in your model. The path and column name above are examples. Replace them with your own file and column.
Doing a common cleanup
A typical first task is removing columns you do not need and fixing a data type. In the editor:
- Select the query in the Queries pane.
- Hold Ctrl and click the headers of the columns you want to keep.
- On the Home tab, choose Remove columns, then Remove other columns.
- Click the data type icon at the left of a column header and choose the correct type, such as Decimal number or Date.
- Rename the query in Query Settings to a clear table name, such as Sales.
Each action appears as a new line in Applied Steps. When you are done, choose Close & Apply on the Home tab. Power BI Desktop runs the query, loads the result into the model, and returns you to Report view.
Data types: two places, two meanings
The data type you set in Power Query Editor and the one shown in Table view can look like the same setting. They are not the same step.
- In Power Query Editor, a type change is a step in the query. It converts the values as they are loaded. If a conversion fails, the cell shows an Error.
- In Table view, the Data type setting on the Column tools tab describes the loaded column in the model.
As a rule, fix types in Power Query Editor, where the conversion is recorded and repeats on refresh. Use Table view for formatting, such as currency symbols, decimal places, and date display, which do not change the underlying value.
Where measures fit
Measures from the DAX chapter do not belong in Power Query Editor. A measure such as Total Sales = SUM(Sales[SalesAmount]) is calculated at report time, in response to filters on the page. Power Query steps run once per refresh, before any report filter exists. If you need a value that is fixed per row and does not respond to filters, add a column in the editor. If you need a total that changes with the page, write a measure.
Common errors
Changes seem to vanish after refresh. If you edited data in Table view, you did not. Table view is read-only for values. Fix the data in Power Query Editor so the fix is repeated on each refresh.
The source file moved. The Source step stores the file path. If you move or rename the file, refresh fails with a message that the file cannot be found. Open Transform data, select the Source step, and update the path. Alternatively, choose Data source settings from the Transform data dropdown and use Change Source.
Close & Apply was skipped. Changes made in the editor stay pending until you apply them. A yellow banner in Report view says there are pending changes. Select Apply changes to load them.
A step breaks after you reorder or delete an earlier step. Later steps refer to columns by name. If you delete a step that created or renamed a column, a later step can fail with an error that a column was not found. Delete or fix the later step too.
Changing a type at the wrong point. A type change placed before a step that adds text, such as a footer row, can produce errors. Clean the rows first, then set the types.
Why order of work matters
Doing shaping in the editor first saves rework. Relationships in Model view depend on matching columns that have the same data type. If the key column is text in one table and a number in the other, the relationship may fail or give wrong results. Align the types in Power Query Editor, then create or review relationships.
A practical sequence for a new report is:
- Load with Transform Data.
- Clean each table: remove columns, set types, rename.
- Close & Apply.
- Check the result in Table view.
- Confirm or set relationships in Model view.
- Build visuals and measures in Report view.
You can return to the editor at any time. After a change, Close & Apply reloads the data, and Report, Table, and Model views reflect the new shape.
Exercise
You loaded a CSV file, and the OrderDate column shows as text in Table view. You change its Data type to Date in Table view. Next week the source file is refreshed with a few blank rows at the bottom and the dates stop working. Where should you make the fix so that it is repeated on every refresh, and why?
Show answer
Fix it in Power Query Editor. Add a step that filters out the blank rows, then set OrderDate to the Date type after that step. Query steps run on every refresh, in order, so the cleanup and type conversion are repeated each time. The Table view setting describes the loaded column but does not clean the incoming rows.
Exercise
A teammate wants a "Total Sales" number that changes when a user selects a region in a slicer. Should it be built in Power Query Editor or as a DAX measure?
Show answer
Build it as a DAX measure, for example Total Sales = SUM(Sales[SalesAmount]). Measures are calculated at report time and respond to slicers and filters. Power Query steps run only at refresh and cannot see report selections.