Excel Script - Refresh data

Copper Contributor



I have an excel file which has a data connection. I have been trying to get the data and associated pivot tables to refresh through a script but it doesn't seem to work fully. The script is as follows:


function main(workbook: ExcelScript.Workbook) {
  // Refresh all data connections


I am prompting the script to run through PowerAutomate a couple of times a day. The file will appear to be modified (last modified date of file reflects when the script was last run through PowerAutomate) but the data in the Pivot table is not up to date from the data source.
If I open the file online will get a message to enable the queries so I don't know if this needs to be part of the script too?


Any thoughts? 
5 Replies
Hi, I am having the same issue. Did you find any solution?

@PDTaylor Currently, pivot table refresh/Power Query refresh is not supported with Office Scripts. If you would like to see this feature in the Office Scripts feature-set, please upvote this request here: Enable Office Scripts to refresh Power Query queries · Community (microsoft.com)

Petra, any other suggestions for how with PowerAutomate/OfficeScripts to 'refresh' a query and pivot table ? Want to get to use PowerAutomate to send the latest info including a refresh.


I used your code and it did not work
I did not get an error message but the pivot table just did not refresh
 by adding () at the end and it works


sample code


function main(workbook: ExcelScript.Workbook) {
  // Refresh Pivot Tables
I know it is a bit late but perhaps someone still has some use for this
This one works, thank you!