Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Can we enable folding for custom query

Hi,

Can we enable query folding for Custom SQL script.

I used a simple Query in advanced option under the database connectivity -  "Select * from Table1" 

and than add basic transformation in power query like filtering data - but the step is not query folded(native query greyed out)

-------------------------

So I added one step just prior to tranformation(Filter data) by using Mcode

=Value.NativeQuery(Source,"Select * from Table1",null,[EnableFolding=true])

but this M code throws error - 

---------------------------------

but when I removed the query from the advanced option under the database connectivity -  "Select * from Table1"

and simply pull the table by passing server and database name, and applied the same logic with Mcode it's working.

 

So here my question is if we pass the custom query - How we can enable the folding for custom query?

2 ACCEPTED SOLUTIONS
ppm1
Solution Sage
Solution Sage

Are you saying you are putting your "SELECT * ..." in both places? (the Advanced Options area of the connector popup window and within Value.NativeQuery) You should only put it in Value.NativeQuery, to get the desired folding behavior. You can add a step in your query with your SQL statement as text and use that within Value.NativeQuery, to simplify your code. The advanced options box should be empty.

 

Pat

 

Microsoft Employee

View solution in original post

jennratten
Super User
Super User

Hello - query folding happens automatically when the data source and transformations support folding.  Queries can fully folded, partially folded or not folded at all.  There are many sources and transformations that do not support folding.  Value.NativeQuery simply represents what Power Query generates and submits to the source to fulfull the query.  The use of custom functions does not necessarily break or prevent folding.  If the source and all of the steps in the custom function support folding, the result will be folded.  One way to get as much of your query to fold as possible is to use simple transformation steps and make sure you apply foldable steps before non-foldable steps, if possible.  Here are some good resources related to query folding.

https://learn.microsoft.com/en-us/power-query/power-query-folding 

https://learn.microsoft.com/en-us/power-query/best-practices 

https://blog.crossjoin.co.uk/2018/11/21/query-folding-web-service-power-bi/ 

http://petcu40.blogspot.com/2019/06/m-folding-in-enhanced-engine-of-power.html 

 

View solution in original post

6 REPLIES 6

Hi Dhirus,

Please watch this video: https://youtu.be/_8WUVlYGekk

jennratten
Super User
Super User

Hello - query folding happens automatically when the data source and transformations support folding.  Queries can fully folded, partially folded or not folded at all.  There are many sources and transformations that do not support folding.  Value.NativeQuery simply represents what Power Query generates and submits to the source to fulfull the query.  The use of custom functions does not necessarily break or prevent folding.  If the source and all of the steps in the custom function support folding, the result will be folded.  One way to get as much of your query to fold as possible is to use simple transformation steps and make sure you apply foldable steps before non-foldable steps, if possible.  Here are some good resources related to query folding.

https://learn.microsoft.com/en-us/power-query/power-query-folding 

https://learn.microsoft.com/en-us/power-query/best-practices 

https://blog.crossjoin.co.uk/2018/11/21/query-folding-web-service-power-bi/ 

http://petcu40.blogspot.com/2019/06/m-folding-in-enhanced-engine-of-power.html 

 

ppm1
Solution Sage
Solution Sage

Are you saying you are putting your "SELECT * ..." in both places? (the Advanced Options area of the connector popup window and within Value.NativeQuery) You should only put it in Value.NativeQuery, to get the desired folding behavior. You can add a step in your query with your SQL statement as text and use that within Value.NativeQuery, to simplify your code. The advanced options box should be empty.

 

Pat

 

Microsoft Employee

Hello @ppm1 ,
I have similar question on query folding. Not sure what steps I need to follow for query folding for custom scripts.

I have basic sql scripts like : Select column1, column2,....from table1 where condition1=true

So, my question is for custom queries, how do I do query folding?

I have following steps but gives me 'Expression.SyntaxError:Token',' expected'. Don't know where it is asking for that token.

Steps:

1. Get data from sql server, provided server name, database name

2. Added custom steps and modified the steps as below:

 =Value.NativeQuery(Source,"Select column1,column2,....",null,[EnableFolding=true])

3. This is giving error, why?

 

pthapa_0-1714403593094.png

Please help me understand the right approach.

Thanks,

pthapa

Anonymous
Not applicable

@ppm1 , 

Thank you !

I thought even if I wrote custom query in Advanced option than it should also be query folded.

You're welcome!

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors