Power BI Query Folding is a key performance optimization concept that determines how efficiently data transformations are executed — ideally pushing as much processing as possible back to the data source rather than performing it inside Power BI.
In simple terms, query folding means that Power BI translates the steps you apply in Power Query (M language) — like filters, joins, group by, or column removals — into a native query that the underlying data source (for example, SQL Server, Oracle, or PostgreSQL) can understand and execute.
When folding happens, the heavy lifting (data filtering, aggregation, etc.) happens at the source level, which is much faster and more efficient than pulling all data into Power BI and transforming it locally.
Let me explain with a practical example —
Suppose I have a large sales table in SQL Server with 10 million records, and I apply a filter in Power Query to load only the last one year’s data.
If query folding is active, Power BI will generate an SQL statement like:
SELECT * FROM Sales WHERE SaleDate >= '2024-01-01'
This means only that one year’s data will be fetched from SQL Server — saving both time and memory.
However, if query folding breaks (for instance, after using a transformation that the source doesn’t support), Power BI will first pull all 10 million records and then apply the filter locally — which significantly slows down refresh performance.
I’ve faced this issue before while merging queries or adding custom columns that used complex M functions. To troubleshoot, I used the “View Native Query” option in Power Query. If it’s enabled (not greyed out), it means query folding is still happening. If it’s disabled, folding has broken at that step.
To maintain folding, I follow a few best practices:
- Keep filtering and transformations that can be translated into SQL (like filtering rows, removing columns, grouping) as early as possible in the query.
- Avoid unnecessary complex custom M code or operations like referencing multiple queries unnecessarily.
- Use database views or stored procedures when transformations get too advanced for Power BI to fold automatically.
A limitation is that not all data sources support query folding — for example, flat files like Excel or CSV, and certain web APIs. In those cases, transformations are always done locally within Power BI.
In short, Power BI Query Folding improves performance by letting the data source handle transformations instead of Power BI, leading to faster refreshes, reduced memory load, and better scalability — especially when working with large datasets.
