Forum Discussion
Referenced Query and Caching question - explanation/confirmation required
Hi,
Before I delve into my question I will declare that I have read the below article but I still have questions regarding my specific scenario:
https://blog.crossjoin.co.uk/2016/11/20/referenced-queries-and-caching-in-power-bi-and-power-query/
I have a Power BI report, well only the Power Query (PQ) part is complete at the moment.
The PQ model contains 14 tables. However, only a single table connects to the SQL Server database. This single table's connection (Import Mode) does contain a SQL statement to Query-Fold the statement up-stream to the SQL Server database.
The resulting table name is 'K8 Extract'. The full APPLIED STEPS for this table is Source then Changed Type. No other steps are applied.
The 13 remaining tables all reference the 'K8 Extract' table and then go on to do a lot unqiue steps (aggregation, grouping, clauses, etc..) thus resulting in greatly different result-sets - hence the need for 13 separate tables.
As the 'K8 Extract' table is the only PQ table that actually connects to the SQL Server database, I am expecting that the SQL Server database to only get queried the once. This is my understanding and aim.
However, when I do a data refresh from within the Power BI side of PBI Desktop I see the following:
At the same time as the above moment in time, I executed a SQL query againt the database the PQ table's SQL statement is running against and it returns the below result:
The TEXT column's value of 'SELECT eoft.branch_code....' is the actutal SQL statement that is executed against the SQL Server to return the 'K8_Extract' table.
As I am seeing the 'SELECT eoft.branch_code....' multiple times in the above SQL, and as I am seeing mutiple entries in the Apply query changes box, all referencing the same SQL Server/database, I am led to believe that the SQL Server, that I only want to query just the once, is indeed being queried multiple times.
Am I correct in my observation?
What do I need to do (set/configure) so the source SQL Server/database is only query the once and the other 13 tables just reference the 'K8 Extract' table and do not impact the source SQL Server/database over and over?
Thanks in advance.
8 Replies
- v-piga-msftResident Rockstar
Hi Anonymous ,
Actually, if you reference the table from SQL Server in query editor, the underlying data source will be queryed in SQL Server.
What do I need to do (set/configure) so the source SQL Server/database is only query the once and the other 13 tables just reference the 'K8 Extract' table and do not impact the source SQL Server/database over and over?
As aworkaround, you could export your table in SQL Server to excel and then get data with Excel connector in power bi so that it will not query in the sql server.
Hope ImkeF and Greg_Deckler have other ideas.
Best Regards,
Cherry
- AnonymousNot applicable
v-piga-msft - thanks for your reply.
"Actually, if you reference the table from SQL Server in query editor, the underlying data source will be queryed in SQL Server."
If I have understood you correctly then yes I am aware that if you place a SQL query inside the 'SQL statement' part of a SQL Server connection (Import Mode) then the query itself will be executed upstream on the actual SQL Server database. This is my intention.
"As aworkaround, you could export your table in SQL Server to excel and then get data with Excel connector in power bi so that it will not query in the sql server."This wouldn't be an option due to company specific reasons.
More importantly, I would like all steps to be handled in Power Query so I am keen to understand if what I have stated, in my first post, is to be expected and therefore I have mis-understood the query-folding aspect, or do I need to configure things differently so to get my desired intention of querying the SQL Server database just the once??- StachuCommunity Champion
I think the essential part of the article in reference to your problem is here:
However, because buffering happens in memory and is not persisted on disk, buffering during the load of one query does not affect the load of another query. If Q1 is buffered when Q2 is loaded, Q1 will be re-buffered when Q3 is loaded.
In other words if you load 14 tables loaded to your model there will be at least 14 calls to SQL Server. If you now have more (e.g. you reference the original table multiple times in ne query) then you can try using Table.Buffer()
https://docs.microsoft.com/en-us/powerquery-m/table-bufferand change all the references within a particular query to the buffered table
disabling the background data preview should also reduce the number of queries during development time, as described here: