Power Automate: update an excel file with Power BI

In this article, I will explain the way to update an excel file from Power Automate in an automatic way. If you prefer to do it via a button, read Power Automate: update an excel file from Power BI. First, from an excel file, I have to create a table that is connected to Power BI (read Excel: connect to Power BI) then a script to refresh the connection by clicking on “automate -> new script”:

power automate

Delete everything and put the below code:


function main(workbook: ExcelScript.Workbook) {
    workbook.refreshAllDataConnections();
}              
              

I will change the name before to save it:

power automate

NOTE: for an effective purpose, the script should only contain the refresh line, if I want to add more codes like copy, delete, etc. I have to create another script

Once done, from the Power Automate webpage, I will click on “create” then I will choose one of those 2 options:

power automate

Based on the choice, the first popup window will be different but after, it is the same:

  • Automated cloud flow: to select if I want to update the excel table automatically based on a specific action. Amongst the options, I select the one that fits better to my need then click on “create” to get this view:
    power automate Click on the option to fill all fields from the left panel that just appears:
    power automate
  • Scheduled cloud flow: to select if I want to update the excel table automatically based on a date. Click on “minute” to see more options. For my example, I select “week”:
    power automate Click on the option to make appear the left panel then fill only the “time zone” field:
    power automate

Let’s keep with the date. From now, the following steps are the same for both. Click on the “+” to add a new step then in the “search” field, put “run script” to select this option:

power automate

Fill all the fields:

power automate

On the top right side, click on “save” then on “test”:

power automate

If all go well, this message will show:

power automate

To run my flow in live action, click on “back” (top left, next to the name):

power automate

Click on “run” then I can see the status of it:

power automate

And in my excel, I can see that the update has been done:

power automate power automate

Interesting Topics