Here’s a fun trick: Using Power Automate (Previously called Microsoft Flow) to refresh a Power BI dataset via button click in a Power BI report! Let’s say that a user needs to kick off a refresh for some reason. It is sometimes difficult to explain where the user should go to manually refresh the dataset behind the report. Instead of telling them to navigate to Workspaces, then click on Datasets, find the dataset with the same name as the report, click the little refresh icon, etc… You can give them a button within the report to kick off the refresh! This trick involves using both Power Automate and another awesome technology called WrapAPI.

For this demonstration, I have connected to a web data source that refreshes virtually instantly. I then created a calculated column to provide the last refresh time to verify that method works properly. The DAX needed for the calculated column uses the UTCNOW() function and subtracts 5/24 to return Eastern time (change accordingly depending on your time zone). This logic is necessary because your Power BI Desktop client will return your current time when using the NOW() function while Power BI Service will return UTC time. The final code is as follows:

 

Last Refreshed = UTCNOW() – 5/24

 

Throwing the new column into a card and then adding a button for the eventual refresh action, our simple report looks like this:

As of right now, the button does not have an action associated with it. Publish the report to Power BI Service. This is an important step because we will need the dataset id from your Power BI portal.

Next, let’s hop over to Power Automate and set up a flow to refresh the dataset. On the left side click Create -> Automated Flow -> Skip. This will set you up with a blank flow. In the search bar at the top, search for “Http” and select When an HTTP request is received. You don’t have to change anything to the step that it creates. Simply click New step below and select Refresh a dataset with the Power BI logo. Select your workspace and dataset for the report that you just published.

Once you save the flow, click on the HTTP step to expand its details. You can see in the above screenshot that there is an “HTTP POST URL.” Click the little copy button and paste it in a browser to see its contents. This is the URL that you need to call to kick off the refresh action, BUT it needs to be a POST request. In short, if you call the URL from a web browser you are sending a GET request which will not work. In order to send a POST request, we need a bit of help from WrapAPI.

Head over to wrapapi.com and sign up for an account. They have a very generous free account which allows you call an API 30,000 times per month for free. WrapAPI is perfect for our purposes because it will allow us to create a separate API endpoint that we can trigger with a GET request that can call our Power Automate flow via a POST request!

Without further ado, create a new API by navigating to wrapapi.com/api. Copy your POST URL from Power Automate and paste it into the top URL bar. Also make sure to change the request from GET to POST!

Finally, there are four Query string parameters that we have to add to make the flow run properly. The first three will be identical to mine and the last will be specific to you. To find the fourth parameter, paste the Power Automate POST url into your browser again and copy everything after sig= at the very end of the URL. See the following screenshot for the finished solution (I’m showing my production version so I’m using a different Power Automate URL than the previous picture).

Once you’ve completed the Query strings, save your solution and click the Publish button. It will provide your final WrapAPI link that you can call at will. Copy this link and paste it in the Action field of your button in Power BI. Remember to change the action type to Web URL.

With that, you can now click on the button and kick off the WrapAPI call which will kick off the Power Automate flow which will kick off the dataset refresh!

The awesome part of this solution is that you can share the report with ANYBODY either within your organization or publicly and the link will work to refresh the dataset. Keep in mind that you are still limited to 8 refreshes per day, so use this method sparingly.

If you liked this trick, make sure to subscribe to the BI Elite Blog and YouTube channel! Happy learning!

Discover more from BI Elite

Subscribe now to keep reading and get access to the full archive.

Continue reading