Forum Discussion

Birinder's avatar
Birinder
Icon for Helper III rankHelper III
4 years ago
Solved

Can I use the same query steps for every excel file ?

Hi there, I have some analysis to perform on some files. Though only file name changes, but data types and column names remains the same for every file. I have created 5 queries to load data into 5 ...
  • BA_Pete's avatar
    BA_Pete
    4 years ago

    OK, so in Power Query you will have the query on the left-hand side that contains the transformations you want to do. Let's say the file you did this on is called XL1.xlsx, and the query is called XL1.

    Right click on the name of the XL1 query on the left of the page.

    Select 'Duplicate' from the dropdown list. This will create a new query called 'XL1 (2)'. Change the name of this query to XL2 from the right-click menu.

    Select XL2 from your query list and, from the Home tab ribbon, select Advanced Editor:

     

    This will open up the M code for the XL2 query.

    At the top of this code, you will see the filename (still your/path/folder/XL1.xlxs) as per my previous post.

    Replace the XL1 filename with the XL2 filename then hit OK.

    Rinse and repeat for XL3, XL4 etc.

     

    If you are using Power Query within Excel, and not within Power BI, then you can open the advanced editor as above and just copy the whole M code, then paste it into a blank query in your new Excel workbook. Chances are that the source line will include something like 'This.Workbook' or similar, so it will just apply the code steps to the currnet workbook you have pasted it into.

     

    Pete