Forum Discussion
Copying several files including power query into a new folder
My knowledge is limited in PQ, but as far as I could understand the problem...
When copying several Excel workbooks that are connected through Power Query and Pivot Tables to a new folder, it is important to update the data source references in Power Query to ensure that the connections continue to work. One way to do this is by using a parameter in Power Query to define the folder path where the source files are located. This way, when you copy the files to a new folder, you can simply update the value of the parameter to reflect the new folder path, and all the data source references in Power Query will be updated automatically.
To set up a parameter for the folder path in Power Query, you can go to the Power Query Editor and select “Manage Parameters” from the “Home” tab. In the “Manage Parameters” window, you can create a new parameter and set its “Name”, “Type” (e.g., Text), and “Current Value” (e.g., the current folder path where your source files are located). Once you have created the parameter, you can use it in your data source queries by referencing it using the “@” symbol followed by the parameter name (e.g., @FolderPath).
For example, if your data source query currently looks like this:
let
Source = Excel.Workbook(File.Contents("C:\OldFolder\SourceFile.xlsx"), null, true),
...
in
...
You can update it to use the @FolderPath parameter like this:
let
Source = Excel.Workbook(File.Contents(@FolderPath & "\SourceFile.xlsx"), null, true),
...
in
...
This way, when you copy your files to a new folder and update the value of the @FolderPath parameter to reflect the new folder path, all your data source queries will automatically use the new folder path.
I hope this helps!
- cpartridgeApr 10, 2023Copper ContributorGreat!! This is helpful to know the code I would use to specify the specific workbook using a parameter. Previously, I seemed only be able to specify the folder directory, and wasn't sure what code to use to specify the exact file.