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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
AGo
Post Patron
Post Patron

Query folding not working without message errors

Hello,

I'm trying to use query folding in order to activate incremental refresh.

This is my query:

let
Source = Value.NativeQuery(PostgreSQL.Database("server", "db", [CreateNavigationProperties=false]), "select * from table1#(lf)union select * from table2", null, [EnableFolding=true]),
#"Filtrate righe" = Table.SelectRows(Source, each [timestamp] <> null and [timestamp] <> ""),
INCREMENTAL = Table.SelectRows(#"Filtrate righe", each [timestamp] >= RangeStart and [timestamp] < RangeEnd),..........

 

RangeStart and RangeEnd are parameters requested to activate incremental refresh.

If I click on Show Native Query on the INCREMENTAL step (which is the last step with this option) it returns correct sql with WHERE statement.

If I look on my postgres db at the query received by DBMS that is running, it is not the folded query but the first one declared in the Source step of mquery.

How can I solve this?

 

Thanks

4 REPLIES 4
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @AGo.

 

Patrick tells in this video that there is no query folding at Native Query.

https://www.youtube.com/watch?v=DWbh7xp08l0

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Are you sure? Whene he's speaking about query folding non-functioning the function he's using doesn't contains a Value.NativeQuery function. I instead succeed in viewing the native query result on my third step, the problem is that PowerBI doesn't send it to the DBMS correctly.

Maybe @ImkeF can help.

 

Thanks

ImkeF
Community Champion
Community Champion

Hi @AGo 

To my knowledge, Query folding will stop after you've used individual SQL code.

In your case, in the Source-step.

So your result doesn't surprise me.

But what I find surprising though, is that the native queries are shown in the subsequent steps.

How sending that query in the first step (Source) instead?

 

Edit: Check this post how to include query parameters into native SQL-calls: https://community.powerbi.com/t5/Desktop/Parameterized-SQL-Query-with-query-folding/td-p/171503 

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @AGo ,

 

are you sure that you see the query of the last step and not the query of the preview cache?

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.