Forum Discussion

KasperJ90's avatar
KasperJ90
Helper III
4 years ago
Solved

Update data in Excel file with PQ linked to another workbook

Hi

 

I created a Excel file that is getting data from another Excel file located in our shared folders. I want that when someone copy in a new file to that location (with same name) then my Excel file automatically updated PQ/Tables with the data from the new file.

 

How do I do that?

  • Hi, KasperJ90 

     

    After my testing, this is done automatically.
    When you copy a new file to replace the old file in the same path, and you click Refresh button in Excel, then it will automatically get the data from the new file.
    Whether you are getting data from an Excel file or from a folder, make sure that the steps for getting data from a file are the same in PowerQuery, then when you replace the old file, the file path is the same and all the query steps are the same, you will automatically get the data from the new file after you click Refresh.

     

    Result:

    code:

    let
        Source = Excel.Workbook(File.Contents("C:\Users\Administrator\Desktop\Shared folder\file.xlsx"), null, true),
        Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
        #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Date", type date}, {"Value", Int64.Type}})
    in
        #"Changed Type"
    let
        Source = Folder.Files("C:\Users\Administrator\Desktop\Shared folder"),
        #"C:\Users\Administrator\Desktop\Shared folder\_file xlsx" = Source{[#"Folder Path"="C:\Users\Administrator\Desktop\Shared folder\",Name="file.xlsx"]}[Content],
        #"Imported Excel Workbook" = Excel.Workbook(#"C:\Users\Administrator\Desktop\Shared folder\_file xlsx"),
        Table1_Table = #"Imported Excel Workbook"{[Item="Table1",Kind="Table"]}[Data]
    in
        Table1_Table

     

     

    Best Regards,
    Community Support Team _ Zeon Zheng


    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Hi, KasperJ90 

     

    After my testing, this is done automatically.
    When you copy a new file to replace the old file in the same path, and you click Refresh button in Excel, then it will automatically get the data from the new file.
    Whether you are getting data from an Excel file or from a folder, make sure that the steps for getting data from a file are the same in PowerQuery, then when you replace the old file, the file path is the same and all the query steps are the same, you will automatically get the data from the new file after you click Refresh.

     

    Result:

    code:

    let
        Source = Excel.Workbook(File.Contents("C:\Users\Administrator\Desktop\Shared folder\file.xlsx"), null, true),
        Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
        #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Date", type date}, {"Value", Int64.Type}})
    in
        #"Changed Type"
    let
        Source = Folder.Files("C:\Users\Administrator\Desktop\Shared folder"),
        #"C:\Users\Administrator\Desktop\Shared folder\_file xlsx" = Source{[#"Folder Path"="C:\Users\Administrator\Desktop\Shared folder\",Name="file.xlsx"]}[Content],
        #"Imported Excel Workbook" = Excel.Workbook(#"C:\Users\Administrator\Desktop\Shared folder\_file xlsx"),
        Table1_Table = #"Imported Excel Workbook"{[Item="Table1",Kind="Table"]}[Data]
    in
        Table1_Table

     

     

    Best Regards,
    Community Support Team _ Zeon Zheng


    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.