Power Query

Query Folding

Should the warehouse pack only what you need, or should a truck bring everything to your office for you to sort? Folding is the first option.

What it means

Power Query can translate your steps into the source’s own language, usually SQL, and let the source do the work. That translation is folding. A step that cannot be translated usually means later work runs inside Power Query, on your machine or gateway. That is not an absolute rule: the engine may reorder steps while optimising, and in uncommon cases a later step still folds.

Build a query and watch the work move

Imagine H Mart’s FactSales lives in SQL Server: 25,000 rows and 36 columns. The row counts are real, but this is a simplified teaching model: it treats every step after a break as local and does not reorder steps. It is not a measurement.

Start from

Steps that usually fold

Steps that often break folding

    25,000Rows sent to Power Query
    9,00,000Cells sent (rows × columns)
    0Steps run locally

    What the source receives

    What keeps it and what breaks it

    Usually folds on SQL sources

    • Filtering rows
    • Choosing or removing columns
    • Group by and sum
    • Merging tables from the same source
    • Renaming and sorting

    Often breaks it

    • Adding an index column
    • Custom M functions with no SQL equivalent
    • Table.Buffer
    • Merging across different sources
    • Pivot or unpivot on some connectors

    Never folds

    • Excel and CSV files, because they have no engine to do the work
    • That includes the H Mart data set and the Power Query exercises, so practise the idea here and check it on a database at work

    This varies by connector and version, so never assume. Check it instead.

    How to check in Power BI Desktop

    1. Open Transform data and right-click the last applied step.
    2. If View Native Query is available, that step folded, and you can read the SQL. If it is greyed out on a source that normally offers it, that step has probably stopped folding. Availability depends on the connector.
    3. Query Diagnostics in Desktop shows what was sent to the source. Step folding indicators and the query plan are available only in Power Query Online, such as in dataflows.

    Why a CA should care

    On a ledger of crores of rows, folding can be the difference between a refresh of minutes and one that fails. Incremental refresh also relies on the date filter folding. The habit is simple: filter and remove columns first, then do the steps that cannot fold.