How to reuse a query created in Query Editor or Power Query
This short blog explains how you can copy and paste the steps of a query that you've created in Power Query (within Power BI Desktop). The steps also work for queries created in Power Query within Excel.

Posted by Andy Brown on 29 November 2017

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Reusing a Power BI Desktop Query or Power Query

The Query Editor in Power BI Desktop (also known as Power Query in Excel) is an amazing tool, but does it allow you to re-use queries that you've created?  It turns out that the answer is yes - this blog shows how.

Firstly, create your query:

Creating a query

You should end up with a series of steps that you want Power BI Desktop to follow to transform your data.

 

Now go to the Power BI Desktop advanced editor:

Advanced Editor

Click on this tool on the HOME tab of the Query Editor ribbon.

Copy and paste your query:

Copying a query

Select the test which constitutes the query, and copy it to your clipboard.

 

This is the underlying language used in Power Query, and is actually called M for short.

In another Power BI Desktop file, choose to create a new query:

Create a blank query

Choose this menu option to create a blank query (you have to have some query to work with, otherwise the Advanced Editor button isn't selectable in Query Editor).

 

Click on the Advanced Editor button again:

Advanced editor button

Choose to go into the advanced editor a second time.

Delete the existing rather pitiful query:

Deleting a query

Select the existing query text, and delete it.

 

You can now paste in the other query's code to recreate its steps!

The above method shows how to copy a single query.  There is an ingenious way to copy all of the queries you have in Query Editor, but it only works if you're using Power Query within Excel (it involves pretending to send feedback to Microsoft, and ticking the Include Formulas checkbox).

This blog has 0 threads Add post