Imagine a scenario where your Power BI dataset does not show the latest data, for example, if you are in between a scheduled hourly or daily refresh, and your boss needs to see the latest and greatest data in a Power BI report. And, you’re out on the road. There’s a few ways to solve this problem (in another post I show building a Power Automate button). In this post, we will build a Power App that will do the refresh at the click of a button. We will also throw some Power BI tiles onto the App, which means the user may not even need to use the native Power BI app if you wanted to give them a custom Power BI app. Power Apps has a cool feature where you can connect to your Power BI instance through the Power BI Preview Connector and perform Power BI functions. Let’s do it.
First, let’s head over to https://make.powerapps.com/ and create a new Canvas app:
We will call the app Refresh Power BI App set the Format to Phone (we want users to use their Smartphone on the go to refresh the Power BI data source in our scenario):
In the app maker, go to Data Sources and search for and select Power BI:
Click on Power BI. We now have a connection to Power BI in our app:
Let’s add a button that will do the refresh. Click Insert->Button and we will set the text to Refresh Power BI:
Click Advanced and go to the OnSelect action. We will change this to perform the refresh:
Enter the code PowerBI.RefreshDataset. We see it requires a groupid and datasetid:
To get the Workspace GroupId, click on a Workspace in the Power BI Service. We have an app called Warehouse, with a Dashboard called Sales:
In the URL, you will see a format like https://app.powerbi.com/groups/ade7c4e4-1bdd-4472-8aa5-744febb1c8e6/list/dashboards?ctid=e6cca260-b075-4884-bc8e-54b7349f1f42, with the GroupId next to /groups/.
To get a DataSetId, click on a Data Set:
The URL looks something like https://app.powerbi.com/groups/ade7c4e4-1bdd-4472-8aa5-744febb1c8e6/datasets/8ca80576-866c-4a1b-af6f-e6c4a0004703?ctid=e6cca260-b075-4884-bc8e-54b7349f1f42, with the DataSetId next to the /datasets/.
Add the code, where the first parameter is the Group Id and the second is the DatasetId:
It should now look like below:
Let’s now add a Power BI Tile that will display some data from the Power BI service:
We have a tile in the Power BI Service called Top Accounts by Revenue in a Sales dashboard:
Add that to the Power App:
Let’s Save the App. It is now ready to be used:
On my phone, I’m logging into the Power Apps mobile app. I see my new app is available:
Click to grant permissions:
Now, I see my button and the Power BI tile, which shows the Top 10 Accounts by Revenue:
Let’s add some data from our data source, which in my case is Dynamics 365. In order to add data to this chart, I will create an Opportunity and “win” it. Let’s create an opportunity for Blue Yonder Airlines for $1,000,000:
And I will close the opportunity:
Now, in the Power App, when I click the Refresh Power BI button, it will perform and refresh and automatically update my chart. We see the big win appearing at the top:
Note you are limited to the refresh limitations based on your Power BI license.
And if you want to, you can see the refresh has occurred by logging into the Power BI service:
A useful piece of code, and look for more options in the future with the Power BI Connector and Power Apps.