Sub topic 16
Close & Apply and refreshing the cleaned data
This chapter covers what happens when you leave the Power Query Editor and how the cleaned data stays current. It assumes you have built a query with several applied steps, set column types, and that your source is a file or database that Power BI Desktop can reach.
What Close & Apply does
While you work in the editor, you only see a preview of the data, which is usually the first 1,000 rows. The query has not yet loaded anything into the report. The load happens when you choose Home > Close & Apply.
On Apply, Power BI Desktop does three things:
- It runs every query that has loading enabled, from the source through all applied steps.
- It writes the resulting tables into the data model. In Import mode, this is an in-memory compressed store.
- It makes those tables and columns available in the Report, Table, and Model views.
The button has a dropdown with three choices.
| Choice | Effect | Editor afterwards |
|---|---|---|
| Close & Apply | Saves query changes, loads data, closes the editor | Closed |
| Apply | Saves query changes and loads data | Stays open |
| Close | Closes the editor. If changes are pending, it asks whether to apply or discard them | Closed |
Use Apply when you want to check the loaded result and keep cleaning. Use Close with discard if you made experimental changes you do not want.
Which queries are loaded
Every query loads by default. Staging queries, parameters, and helper queries usually should not. In the Queries pane, right-click a query and clear Enable load. The query name turns italic. It still runs when another query references it, but it creates no table in the model.
A second, separate option is Include in report refresh. It controls whether the query is re-run when you use Refresh in Desktop. Leave it on for normal tables. Turn it off only for a static lookup table that never changes, to save refresh time.
Disabling load on staging queries keeps the model small and the field list clear. Report authors then see only the tables meant for modeling.
Data types decide the model columns
The data type you set in Power Query becomes the column type in the model. A column left as type Any generally loads as text. That breaks numeric sorting, sums, and date hierarchies. Before you apply, scan each column header icon in the editor and confirm there is no "ABC123" icon, which means Any type.
Locale matters here too. If the source stores dates as 13/02/2026 and you convert with the wrong locale, the conversion yields errors or swaps day and month. Convert with an explicit locale, as in the type step from the first example in this tutorial:
let
Source = Csv.Document(File.Contents("C:\Data\sales.csv"), [Delimiter = ",", Encoding = 65001]),
PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
ChangedType = Table.TransformColumnTypes(PromotedHeaders, {{"OrderID", Int64.Type}, {"OrderDate", type date}, {"Amount", type number}}, "en-US")
in
ChangedTypeThe locale is stored in the step itself, so refreshes on another machine parse the file the same way.
Check the loaded result
Applying does not prove the data is correct. After the load finishes, do these checks:
- Open Table view and look at the row count in the status bar. Compare it with a count you trust from the source.
- Sort a numeric column to confirm that it sorts as numbers, not text.
- Check date columns for the expected range.
- Look for blank cells where you expected values. They are often nulls that came from a failed conversion.
If something is wrong, go back with Home > Transform data, fix the step, and apply again. Only queries that changed, and queries that depend on them, are reloaded.
Refreshing the data
A refresh re-runs the queries against the source and replaces the loaded tables. The saved applied steps are re-executed in order on the new data. That is why cleaning in Power Query pays off: you build the cleaning once, and every refresh repeats it.
There are three kinds of refresh, and they are easy to confuse.
| Where | What it does |
|---|---|
| Editor: Refresh Preview | Updates only the preview in the editor. Does not change the model |
| Desktop: Home > Refresh | Re-runs queries and reloads the model from the source |
| Power BI service: scheduled refresh | Re-runs queries on a schedule for the published semantic model |
Refresh Preview is a common source of confusion. If you see new rows in the editor but not in the report, you have not yet refreshed the model. Choose Refresh in the report window or Apply in the editor.
Making refresh survive change
A refresh fails or gives wrong results when the source changes shape. These are the common causes and fixes.
- A column was renamed or removed in the source. A step that names it fails with an error such as "The column 'Amount' of the table wasn't found." Update the step, or make the step tolerant. Many steps, for example
Table.TransformColumnTypes, acceptMissingField.Ignorewhere it applies. - New junk rows appear. Steps that remove rows by position, such as "remove top 3 rows", break when the layout changes. Prefer filtering on content when possible.
- The file moved. A hard-coded path stops working on another machine. Put the path in a parameter so you can change it in one place.
Here is a parameter used as the source path. The first query is the parameter, and it has Enable load turned off. The second query is the data query.
// Query 1, named SourcePath (a parameter)
"C:\Data\sales.csv" meta [IsParameterQuery = true, Type = "Text", IsParameterQueryRequired = true]// Query 2, named Sales
let
Source = Csv.Document(File.Contents(SourcePath), [Delimiter = ",", Encoding = 65001]),
PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
ChangedType = Table.TransformColumnTypes(PromotedHeaders, {{"OrderID", Int64.Type}, {"Amount", type number}}, "en-US")
in
ChangedTypeTo change the file, edit the SourcePath parameter under Home > Manage Parameters. Nothing else needs editing.
Credentials and privacy levels
The first time you refresh, Power BI may ask for credentials for each source. You can review them later under Home > Data source settings. Cleared permissions force a new prompt.
Privacy levels (Public, Organizational, Private) control whether data from one source may be sent to another during a query. If you combine two sources and see a message about the formula firewall, the cause is usually a mismatch in privacy levels or a step that mixes two sources inside one query. A common fix is to load each source in its own staging query and combine them in a third query.
Refreshing after you publish
Publishing sends the model and its queries to the Power BI service. Scheduled refresh in the service runs the same queries, but from the service's side. A path such as C:\Data\sales.csv is not reachable from the cloud. For files on your computer and for on-premises databases, the service needs an on-premises data gateway installed on a machine that can reach the source. Cloud sources, such as SharePoint Online or Azure SQL Database, do not need one.
Moving the file to a location the service can reach, and using a parameter for its path, keeps the refresh dependable.
Common mistakes
- Treating Refresh Preview as a model refresh.
- Applying before checking column types, so numbers load as text.
- Leaving staging queries loaded, which produces duplicate tables in the field list.
- Hard-coding a local file path in a report that will be scheduled in the service.
- Assuming the first 1,000 preview rows represent the entire source. Problems can hide in later rows and appear only after the full load.
Exercise
You added a new CSV file with 500 more rows to the source folder. The editor preview shows the new rows after you click Refresh Preview, but the report visuals still show the old totals. What did you miss, and what should you do?
Show answer
Refresh Preview only updates the preview in the editor and does not reload the model. Use Close & Apply (or Apply) in the editor, or Home > Refresh in the report window, to re-run the queries and load the new rows into the model. Then confirm the row count in Table view.
Exercise
A query named RawSales is used only as the starting point for a query named Sales. How do you stop RawSales from appearing as a table in the report, and does Sales still work?
Show answer
Right-click RawSales in the Queries pane and clear Enable load. The name turns italic and no table is loaded into the model. Sales still works because queries that reference RawSales run it as part of their own evaluation.