Power Query M basics: read steps, types, and query folding
Power Query M is a functional formula language for connecting to data sources and filtering, transforming, and combining data in Excel, Power BI, and other hosts. Applied steps in the editor are parts of an M query. M is case-sensitive and prepares data for a model; DAX defines analytical calculations over the prepared model.
Power Query M basics: read steps, types, and query folding
Power Query M is a functional formula language for connecting to data sources and filtering, transforming, and combining data in Excel, Power BI, and other hosts. Applied steps in the editor are parts of an M query. M is case-sensitive and prepares data for a model; DAX defines analytical calculations over the prepared model.
From Applied Steps to M
The Power Query editor shows step names and order. Advanced Editor shows the same query as M code. A query commonly defines intermediate steps in let and returns its final result in in. Later steps refer to earlier step names. Source and source are different identifiers because M is case-sensitive. A step name with spaces can use a quoted identifier such as #"Changed Type". Microsoft: M quick tour · Microsoft: M language reference
Read a small query
This self-contained example creates a table, assigns types, filters rows, adds a calculated column, and selects output columns. It is illustrative and was not run against a real source.
let
Orders = Table.FromRecords({
[OrderID = 1, Item = "Pen", Quantity = 2, UnitPrice = 3.5],
[OrderID = 2, Item = "Book", Quantity = 1, UnitPrice = 12.0]
}),
Typed = Table.TransformColumnTypes(
Orders,
{{"OrderID", Int64.Type}, {"Item", type text},
{"Quantity", Int64.Type}, {"UnitPrice", Currency.Type}},
"en-US"
),
KeptRows = Table.SelectRows(Typed, each [OrderID] > 0),
AddedTotal = Table.AddColumn(
KeptRows, "LineTotal", each [Quantity] * [UnitPrice], Currency.Type
),
Selected = Table.SelectColumns(AddedTotal, {"OrderID", "Item", "LineTotal"})
in
SelectedOrders creates two records. Typed assigns column types and provides a culture for interpreting text values. KeptRows filters rows. AddedTotal evaluates the expression for each row; each is a concise function form. Selected keeps the output fields, and in returns that final step. Clear step names make it easier to understand dependencies. Changing step order can change the data meaning, such as whether a filter applies before or after aggregation.
Types and locale
Locale affects how text dates and numbers are interpreted. For example, 03/04/2026 can mean March 4 or April 3 depending on settings. Automatic type detection is convenient but may infer types from inspected rows; it does not guarantee the meaning of the entire source. If source dates use another convention, change type using the correct locale, then verify extracted day, month, and year. Also inspect blanks, decimal separators, and time zones. Microsoft: data types in Power Query
Query folding
Query folding translates supported M transformations into operations that a source such as a database can execute. All, some, or none of the steps may fold. Support depends on the connector, source, and transformation combination. CSV and Excel files have no query engine to receive database folding. Folding may improve efficiency; it does not guarantee performance or validate business meaning. Microsoft: query evaluation and folding
Check whether the connector supports folding.
As an initial design, keep needed columns and apply row filters early; the engine may optimize step order.
In Power Query Online, review folding indicators or the query plan. In Desktop, View Native Query may be available for some connectors and steps, not all.
Observe data volume and source load during an actual refresh. A Desktop preview does not establish full-refresh behavior.
If folding stops, identify the step that changed and decide where the work should run. Do not reorder steps blindly or buffer data without a reason.
When a query combines sources, privacy levels affect evaluation and folding. Power Query can raise a Formula.Firewall error when source privacy levels don't allow the data to be shared, or when a query both references another query and directly accesses a source. Before lowering a privacy level to clear the error, confirm whether the data is allowed to cross that source boundary. Microsoft: Data Privacy Firewall
Handle errors without hiding them
Inspect the error detail and source value first. Correct invalid source values when possible. Remove error rows only when their impact on the metric is understood. If replacing an error, document why the replacement is valid and how it affects later calculations. Keeping error rows can help with review. Microsoft: handle Power Query errors
A safe edit and validation sequence
Check source, credentials, and privacy levels; edit a query copy or development file.
Change one step at a time and review row count, column types, and representative values.
Include representative dates, blanks, duplicate keys, and invalid numbers in the review.
Compare the result with an approved source sample and ensure required relationship or calculation columns remain.
If folding matters, inspect the plan or native-query availability and observe an actual refresh.
If an error appears, undo the last step, inspect error details, and reapply a smaller transformation.
M makes data-preparation procedures repeatable. Start with editor steps, understand their inputs, outputs, and types, then verify folding and error handling against the source and business meaning.