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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rajulshah
Super User
Super User

Native Query > Query not folding after filtered rows

Hello everyone,

 

I have SQL datasource and fetching just one table.
I want to apply Incremental Refresh on the table. Hence, I created 2 parameters - RangeStart & RangeEnd and also both, parameters and the date field both have Date/Time as datatype.

 

So, when I do all the transformations, I am able to see 'View Native Query' as enabled. As soon as I filter the field with these parameters, it becomes disabled.

 

So I tried following alternatives:

  1. I tried to filter the field with just the date values, but I found very weird behaviour. Whenever I had "1st July 2021", it used to show as enabled. But whenever I tried other date value, let's say, "26th June 2021", it again got disabled.
  2. I tried the solution given in this blog but it used to work with a datevalue and didn't work with the Incremental Refresh parameters.
  3. I checked out the video by Patrick but I am not able to get the queries as mentioned by him.

Does anyone have faced this issue or can guide me through it?

Any help would be great.

Thanks in advance.

13 REPLIES 13

Hi @rajulshah ,

 

what kind of database is your data source? (MS SQL?)

To me the "Native Query" is more of an indicator, can you check on the database what query Power BI is really sending?

 

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


Hello @mwegener , thank you for the response.

 

Yes, the query sent to SQL Server has this filter applied, then also it would load all the data in Power BI and then filter it in there.

Hi @rajulshah ,

 

if the filters are present in the SQL query, the query folding will also work and only the data that is needed will be transferred from SQL Server to Power BI.

 

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


@mwegener ,

 

Yes, but what it does is loads all the rows in the Power BI, let's say 10 million and then applies filter to it and in the end, the table will have only filtered rows, i.e 2 million rows.

do you know why it does this?

@rajulshah 

 

When Power BI loads all rows, the filter is not in the WHERE clause of the SQL.
Can you post screenshots of the Power Query Steps and the SQL.

 

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


Sure,

 

Below are the steps of our query:

rajulshah_0-1626517254062.png

But instead of the parameters, even if we use hardcoded numbers, it loads all the data and then filters in Power BI. Also, I have used view, but the native query does not have the filter conditions in it.

Am I doing anything wrong? Please guide.

Hi @rajulshah ,

 

to my knowledge the "Changed Type" step breaks the query folding. Why does the data type need to be changed here?

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


Hello @mwegener ,

 

We are fetching the Date in number format but it is not imported as "Whole Number" but in text format.

 

Hence, we are changing the formats. Moreover, by clicking on this step, I am able to see "Native Query" but not on the next step.

Hi @rajulshah ,

 

maybe you can try the following.

 

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [PurchaseDate] >= Number.FromText(DateTime.ToText(RangeStart, "yyyyMMdd")) and [PurchaseDate] < Number.FromText(DateTime.ToText(RangeEnd, "yyyyMMdd")))

 

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


it unsettles me that Power Query doesn't recognize the column's data type correctly, but never mind.

Can you post a screenshot of the SQL statement as Partrick shows it in his video?
Can you post your function ConvetDateToKey?

 

 

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


Hello @mwegener ,

Thank you for the response, and sorry for the late response.

 

We have already done that using the ConvertDateKey function as shown in Patrick's video.

 

Do you have any idea whether Query Folding is done in a view or not?
Is there any chance that Query Folding isn't happening because we have used a view?

Hi @rajulshah ,

 

Query Folding is also executed on a view, as Power Query queries the database object.

 

At the end of the day, Power Query doesn't care if it has to query a table or a view, since the SQL is the same.

 

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


@mwegener ,

 

Thanks for the response. I don't know what the issue maybe.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.