Professional Documents
Culture Documents
Query Folding - 085243
Query Folding - 085243
Query folding refers to the process of translating and pushing data transformation steps back to the
source database server. This means that instead of retrieving all the data to your local machine and
performing transformations there, Power Query attempts to perform as many transformations as
possible within the data source itself.
Efficiency: Performing operations on the server side leverages the power and performance of the
database server.
Reduced Data Transfer: Limits the amount of data that needs to be transferred over the network.
Optimized Processing: Takes advantage of indexes and optimized SQL queries, resulting in faster data
processing.
Query folding occurs when Power Query can convert a transformation step into a query that the data
source can understand and execute. This is possible when using data sources that support query
languages, like SQL databases (e.g., SQL Server, Oracle, MySQL).
Grouping (Table.Group)
Sorting (Table.Sort)
Joins (Table.Join)
To see if query folding is occurring, you can check the "View Native Query" option in Power Query:
In Power BI Desktop:
Transformations that require complex logic not easily translatable to the source's query language.
Order of Operations: Perform steps that support query folding early in your transformation process.
Simplify Transformations: Avoid overly complex or custom transformations that the data source cannot
natively process.
Leverage Source Capabilities: Use database functions and capabilities as much as possible.
Let’s consider a scenario where you have a SQL Server table and you perform the following steps in
Power Query:
Power Query will attempt to fold these steps into a single SQL query that might look something like this:
sql
Copy code
FROM Sales
ORDER BY OrderDate
Troubleshooting Query Folding Issues
Review Each Step: Check each transformation step to identify which step breaks the folding.
Check Source Compatibility: Ensure the data source supports the transformations you are applying.
Conclusion
Understanding and leveraging query folding in Power Query can significantly enhance the performance
and efficiency of your data transformations. By ensuring that as many steps as possible are folded back
to the data source, you can take full advantage of the processing power of your database server and
minimize data movement.