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
Pace
New Member

No folding on merged queries, SQL statement get's shown but isn't executed, etc.

I'm trying to merge 2 queries. One of them is an (oracle) database view with a column "customerNumber", the other is an Excel sheet that contains the relevant customer numbers for this report. I make sure that the columns have the same data type (in my case text since in some cases there are letters in there), click "Merge Queries" and choose "Right outer Join" with the database Query as the first source and the Excel as the second. The result is something like:

 

#"Merged Queries" = Table.NestedJoin(#"Source", {"customerNumber"}, excelTable, {"column1"}, "table", JoinKind.RightOuter).

 

After this step, "View Native Query" is greyed out, which after some googling i found out indicates that there is no folding. I can confirm this by just applying the changes, since i can tell from the "loaded rows" progress window that it does a full table scan. Next i tried to find out more via the diagnostics options. This feature has insonsistent behaviour. When i click the step prior to the Merge, a step where i removed some rows, and click "Diagnose Step", the diagnostics for this step immediately show up as tables in the left pane. When i do the same for the "Merged Queries" step, nothing happens.

 

I need to click "Start Diagnostics", then do the Merging Step, then "Stop Diagnostics". In the now appearing diagnostics table, there are some SQL statements. Unfortunately, i can't look at them fully, because the viewing window cuts the text off with "..." at the end, with no option to view the whole text. Only when i right click and "Add as new Query", i finally see the SQL statement...

 

Here i see exactly what i was expecting. There is no trace of a WHERE clause that filters for the desired customer numbers. PowerBI loads the whole table, then internally filters for the customer numbers specified in the excel sheet. I can't find the article any more but after lots of googling i found out that by changing the line to 

 

#"Merged Queries" = Table.Join(#"Source", {"customerNumber"}, excelTable, {"column1"}, JoinKind.RightOuter).

 

and running Diagnostics again, i finally get an SQL statement that encapsules the customer numbers in "WHERE customernumber = XXX" clauses.

 

This works as expected in the Data Preview Window. "Refresh Preview" works quick, confirming that there is no full table scan happening.

 

And now here comes the punch line.

If i now click "Close & Apply", it still executes a full table scan.

 

I don't know where to go from here. Diagnostics tells me a correct SQL statement, which then doesn't get executed and PowerBi does a full table scan instead.

 

 

1 REPLY 1
lbendlin
Super User
Super User

That is correct, merges will break query folding. Avoid merges where possible. Implement your join in the data model instead.  Depending on which side of the relationship you take the field from you can emulate your right outer join too. (In your case the column from the Excel side has to come first)

 

If you don't like to pull all rows from the Oracle table then you may consider using views or native queries.

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.