Forum Discussion
Replacing data sources to share point folder and file
- 1 year ago
Hey Anonymous ,
Yes, you can replace the Source step in Power Query using Advanced Editor rather than manually recreating all the steps. This is much faster and safer if done carefully. Power Query steps are sequential. If you only replace the Source step, and the structure of the new file (columns, names, etc.) is the same, the rest of the steps should continue to work as long as the name of the step being replaced remains the same.
Steps Should Follow:
- Open the original query (OneDrive path) → Go to Advanced Editor.
- Copy everything.
- Create a new query using Get Data → SharePoint folder or Web, as needed.
- Open that query’s Advanced Editor and identify the new Source step.
- Paste the old query, but replace the Source line with the new SharePoint source.
- Make sure that all step references are preserved (i.e., don’t change step names like Source unless you update every reference to it).
Original OneDrive Source:
let Source = Excel.Workbook(File.Contents("C:\Users\Me\OneDrive\myfile.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", type text}}) in #"Changed Type"New SharePoint Source:
let Source = Excel.Workbook(Web.Contents("https://mycompany.sharepoint.com/sites/mysite/Shared Documents/myfile.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], ...Replace the first Source line only, and keep the rest of the steps untouched, assuming the structure is the same.
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
The easiest way to do that
It is by using advanced editor in Power query
You have to check what is the different in the applied steps
To do that, in Power query in home, select advanced editor
You should see something like:
let
Source = Excel.Workbook(File.Contents("C:\Users\xxxxxxxxxxx\Downloads\BrewersProduction_2023.xlsx"), null, true),
BrewersProductions_Sheet = Source{[Item="BrewersProductions",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(BrewersProductions_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Department of the Treasury", type text}, {"Column2", type any}, {"Column3", type any}, {"Column4", type any}})
in
#"Changed Type"
You can replaced the first step by the steps for your sharepoint folder,
You just have to be careful when you replaced something with the previous name
In the name of your step, the previous step must be mentionned
#"Promoted Headers" = Table.PromoteHeaders(BrewersProductions_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Department of the Treasury", type text}, {"Column2", type any}, {"Column3", type any}, {"Column4", type any}})
If you need some suppport, you can share the advanced editor code of one sharepoint file and one onedrivefiles (with the steps applied on it)
Kind regards
- Anonymous1 year agoNot applicable
So, just replace the old path with new SharePoint file path?
I am not sure if I understand this completely. I won't have any steps for my new data source. I will just want it to go through the same steps as the previous version. Also, how does it work with Folder?
- Cookistador1 year ago
Super User
Indeed,
Copy the first lines from Sharepoint transformation (you need the step where you extract the values from the csv)
Once you have your raw files in the table, copy the first lines and replace them by the first lines in your one drive table