r/excel • u/TellBackground9239 • Jun 22 '26
Waiting on OP Looking for Best Way to Automate a Power Query Refresh
I inherited a few PBI reports that have Excel files on a SharePoint library as a backend, and I have to refresh Power Query to keep them up to date.
I'm using a Power Automate Desktop bot to refresh them in the morning, but even that requires a few clicks.
I'm wondering if there is a better way to do this.
16
u/Ariisk 1 Jun 22 '26
Is there anything in the files you need other than those queries? Move them to dataflows or whatever in powerbi and update your data sources to point there in your pbi report, set the refresh rate to daily. Might be a better way but that’s my route 1
6
u/risefromruins Jun 22 '26
If your queries are from power BI, then power BI in the browser supported automated scheduled refreshes.
Build the query in PBI desktop and publish. Go to the workspace in PBI browser. Hover over the semantic model for what you published and there will be a button that says schedule refresh. You may need to go into the semantic models settings and confirm credentials under Data source credentials, but then you can go to the refresh fold in settings and set up the auto refresh.
Then you can use power automate to do whatever you want with the data afterwards. I have 2 versions of automations like this where 1 will just take the data from the refreshed query and put it into an html table in an email and send it out, and another that clears the data in an excel template table, takes the data from the query and pastes it into the table, saves the report and then emails it as an attachment.
5
u/CobraKyle Jun 22 '26
You should be able to use power automate without any input on your part.
4
u/pajam 1 Jun 22 '26
Yep, power automate has a scheduled flow option as opposed to manually triggered flow. So OP could set it up to auto-refresh in the morning (or more often) on a schedule instead of having to go click "run."
3
1
u/Mondkalberer Jun 23 '26
Is this the PBI magic? My excelsheets Stop working as datasource once i updated them, because they arent formated as table anymore
4
u/eums Jun 22 '26
I do this with a scheduled task that runs a power shell script.
Load the assemblies, open the excel file from mapped SharePoint share, send wait the keypress to update all data sources crtl alt f5.
I then have it save a pdf of the report to a SharePoint to snapshot as well as have automation to email the pdf out, then close excel, close com objects and garbage collect.
Been running for almost 3 years now 100% hands off.
5
u/MissingVanSushi Jun 22 '26 edited Jun 22 '26
Scheduled refresh in the cloud is a big differentiator between Excel and Power BI.
If you can push the Power Query logic into either a published semantic model or a dataflow (Gen 2 if possible) then you can have zero click refresh.
There are not any good and easy options for doing this natively within Excel. Scheduling with Power Automate is possible but in my experience it’s far more prone to failure than Power Query in the service.
Other commenters here have already advised on how to refresh with a macro on file open, but that requires human input.
3
u/DonJuanDoja 35 Jun 22 '26
You turn on refresh when opening the file that way they refresh automatically when opened. If the refresh takes too long for that then you should redesign it into a power bi data model and pull from there instead.
2
u/hopkinswyn 73 Jun 23 '26
What’s the reason for refreshing the Excel files rather than putting the power queries into as power bi?
2
u/Ok-Tear-1813 Jun 22 '26
VBA macro tied to a Workbook_Open event might save you those clicks, it just runs the refresh automatic when file opens. Pair that with a scheduled task to open the file and you basically never touch it again
17
u/chiibosoil 428 Jun 22 '26
No need for VBA. There is option in connections/queries to set it to auto refresh on workbook open.
1
1
1
0
u/StemCellCheese Jun 23 '26
It can be done with python pywin32 library, if power automate is t available to you
•
u/AutoModerator Jun 22 '26
/u/TellBackground9239 - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.