• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

How do I create a global temp table via Power Query? ##TEMP_TABLE SQL|Power Query|Excel Forum|My Online Training Hub

You are here: Home / How do I create a global temp table via Power Query? ##TEMP_TABLE SQL|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryHow do I create a global temp table…
sp_PrintTopic sp_TopicIcon
How do I create a global temp table via Power Query? ##TEMP_TABLE SQL
Avatar
Martin Short

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
November 19, 2020
sp_UserOfflineSmall Offline
1
November 19, 2020 - 2:41 am
sp_Permalink sp_Print sp_EditHistory

I've got a number of SQL queries that all reference a shared temp table - let's call it ##TEMP_TABLE.

Not exactly an issue in SSMS, but how do I create a global temp table that can be referenced by the other SQL queries in Power Query?

- I tried creating a connection only, but it's really really slow as the temp table is HUGE which makes it a non-starter

- In an ideal non-political world, I would create a view on the server and reference the view, but this isn't possible here.

Any thoughts clever people?

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4446
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
November 19, 2020 - 8:36 am
sp_Permalink sp_Print

Hi Martin,

Welcome to our forum!

I'm not sure what you mean by 'I've got a number of SQL queries...', where are these queries? My reply below assumes the ##TEMP_TABLE is a Power Query query.

You can export your queries to an ODV file and then share them across your workbooks or with co-workers. To export a query definition into an ODC file in Excel 2016 or later, right-click on a query in the Queries & Connections side pane and choose Export Connection File. 

To use the query and import data via the ODC mechanism, click Data > Existing Connections. The Existing Connections dialog will appear, and you can then import from the available ODC files, existing workbook connections or tables.

That said, I'm not sure this will improve performance. If the temp table query is slow, then it'll still be slow here, so perhaps it's better to fix why the query is slow.

Mynda

Avatar
Martin Short

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
November 19, 2020
sp_UserOfflineSmall Offline
3
November 19, 2020 - 6:20 pm
sp_Permalink sp_Print

Hi Mynda

Thanks for the reply and greeting. 

Sorry I thought I had made myself clear in the question.  My bad! 🙂

My temp table is of the form 

SELECT * INTO ##TEMP_TABLE

Obviously much more complicated than that in the real world.

I then have a series of SQL queries inside Power Query that ideally need to reference ##TEMP_TABLE.

That's the bit I don't know how to do - or even if it's possible.

Now I could write the temp table code into every table but that would really slow it down.  I can import data too. 

My question though, is can I employ a global temporary table for SQL server?  Is it possible?

Thanks

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
November 19, 2020 - 11:03 pm
sp_Permalink sp_Print

Hi Martin,

I understand the purpose of the ##TEMP table in SQL Server but are you sure it is necessary to create one in PQ?

I obviously don't know how much data we are talking about, but the way PQ works is that it only loads the data it needs.  Particularly with something like a SQL database.

Initially you will load, for example, the entire table (actually PQ only loads a preview, not the whole lot) and then filter out what you don't want until you get the data you do want.

PQ then creates its own SQL commands to get the SQL server to do the SELECT, filtering, grouping etc.  PQ pushes this back to the SQL server (this is called query folding) so that the SQL server does the bulk of the work and only transfers the data you want.

If you write your own SQL commands in PQ then query folding won't work and generally this makes the query performance worse.

In your case, have you tried just creating a query in PQ and then doing a refresh to see how long it takes?

Regards

Phil

Avatar
Martin Short

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
November 19, 2020
sp_UserOfflineSmall Offline
5
November 20, 2020 - 8:41 pm
sp_Permalink sp_Print

Hi Philip

Thanks for the reply.  It might be unconventional, but I absolutely do want to do this.  Is it possible?

Cheers

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
November 22, 2020 - 11:45 am
sp_Permalink sp_Print

Hi Martin,

You can write a query to create a "temp table" in PQ, but if you are doing this in Excel, the query will load the data from SQL every time you refresh queries.

If you do this in PBI, you can turn off refresh for the query so you'll work with a 'static' table of data.

But once you have this table in PQ you should be using native M to interrogate the data.

Regards

Phil

Avatar
Martin Short

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
November 19, 2020
sp_UserOfflineSmall Offline
7
November 23, 2020 - 3:53 am
sp_Permalink sp_Print

Thanks Phil.  Is it possible to create a GLOBAL temp table?  Or am I obliged to create a connection in PQ.  I would far prefer to keep the global query in tempdb as a ##, but I still haven't found anyone who can tell me if this is possible.

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
8
November 24, 2020 - 12:50 pm
sp_Permalink sp_Print

Hi Martin,

I'm not sure there is an equivalent in PQ to a Global Temp Table, and I'm not sure how you intend to make use of one.

If you create a query in an Excel workbook, or in PBI, the result of that query can be used by other queries in that workbook or PBI file, no problem there.  You just refer to the query by name to access it's result, whether that's a table, a list or whatever.

However a query (the temp table) created in one workbook can't be accessed directly by queries in another workbook.  You'd need to actually copy/paste the query code between workbooks or Export the Connection File for the query, then import that into your new workbook - essentially the same as just copy/paste.

Regards

Phil

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27236

 

Member Stats:
Guest Posters: 49
Members: 31888
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.