Forum Discussion

whatisok's avatar
whatisok
New Member
1 year ago
Solved

Replacing data sources to share point folder and file

I have many Power BI reports that uses one drive paths as data sources, and I want to replace all the data sources to sharepoint folder or individual file, so I can have scheduled refreshes on power ...
  • Nasif_Azam's avatar
    1 year ago

    Hey whatisok ,

    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:

    1. Open the original query (OneDrive path) → Go to Advanced Editor.
    2. Copy everything.
    3. Create a new query using Get Data → SharePoint folder or Web, as needed.
    4. Open that query’s Advanced Editor and identify the new Source step.
    5. Paste the old query, but replace the Source line with the new SharePoint source.
    6. 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