Excel Power Query - How to save a code for future use?

anna99

New Member
Joined
Jan 8, 2021
Messages
26
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Hi all,

I got code from Advanced Editor in excel power query, how can i save this code as a button (same like we did for macro/vba) for future use without copy and paste this code again.

Thank you
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Strange question as Power Query is a script that runs on refresh.
What exactly is your need? What do you try to accomplish?
 
Upvote 0
Strange question as Power Query is a script that runs on refresh.
What exactly is your need? What do you try to accomplish?
Hi Grah, what i meant is i want to save all steps that i created in excel query, so that in future i can use all these steps again for the same data type format. hope it's clear
 
Upvote 0
maybe
saveM.png
 
Upvote 0
But PQ saves those steps...
Still not clear. One can export the connection file and reuse it as well.
 
Upvote 0
@sandy666 , that would be equivalent of copy/paste of code, no? ?
@anna99 , Maybe you need to think PQ more. There are techniques where you can reuse the Query on another file. Using a variable, reading files from folder and select latest, move file to a dedicated folder, rename a source file,... Are a few options.
Hence my earlier question to elaborate on the use case.
 
Upvote 0
If the only thing that changes in the query is the source then you could set up the code to read the path to the source from a named range.
 
Upvote 0
@sandy666 , that would be equivalent of copy/paste of code, no? ?
@anna99 , Maybe you need to think PQ more. There are techniques where you can reuse the Query on another file. Using a variable, reading files from folder and select latest, move file to a dedicated folder, rename a source file,... Are a few options.
Hence my earlier question to elaborate on the use case.
Hi Grah, i always use that for the table i have on an active worksheet. i don't save or get it from a folder. so i think there is no way to save this code somewhere in PQ, i will copy and paste when i need then. thank you anyway
 
Upvote 0
So you have multiple files with some data in a table, structures the same way.
Meaning you can have another file with your PQ which you can connect dynamically to any of the files. Like @Norie mentions you can have a cell filled with the path to the source file and use this cell content as a variable in the source step of your PQ.
That way you do not need to copy the query each and every time.
 
Upvote 0

Forum statistics

Threads
1,223,744
Messages
6,174,253
Members
452,553
Latest member
red83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top