Integrate Power BI into Your Application: Part 4 – Refresh Data Set



Power BI REST API is not just for embedding content or getting list of dashboards and reports. It also has many functions to work with data sets, gateways, and data sources. As one of the many exciting features of that; you can easily refresh a data set from an application. you can refresh it as many as times you want. with any frequency you want. You can refresh your data set after ETL run through a console application. or you can have a service application that kick of refresh even every single minute! There is no limitation for your data refresh anymore! Let’s check it out. if you like to learn more about Power BI; read Power BI book; from Rookie to Rock Star.

Step 1: Register your Application

Step 2: Authenticate

Sample Code

The sample code for this example can be downloaded from here.

Step 3: Get Data Set

With Power BI REST API version 2, you can access many objects from Power BI service. One of these object types is data set. You can get list of data sets, and you can then apply some operations on it, such as refresh. After authenticating, code below gets list of data sets;

GetDatasetsInGroupAsync simply gives you a list of all data sets, and you can then iterate through them. As I’ve mentioned before, group id should be the guid of the group. You can then find the particular data set you want. code below just gets the very first data set in the list:

This data set is already in a group in my Power BI account;


As you can see the data set above, is named Pubs 20170529, and it refreshed at 21st of June 2017 as the last time.

Now with running the code, I can easily find this data set;


After finding the data set, you can easily refresh it.

Refresh Data Set

You can even directly refresh a data set, you just need Id of that data set. one way to find the data set ID is through application. another way is from URL of power bi service. If you go to setting of that data set, you can find the ID of it easily;


the code to refresh a data set is very simple:

As a result of refresh, then you can see the data set is refreshed successfully;


Last refresh time is now 29th of June 2017, 11pm, which is the time of writing this blog post ;)

Imporatnt note to consider here is that this data set is an IMPORT DATA data set, and it is working through gateway. so I need the gateway to be up and running. However, even if you are connected to a cloud data source through import data, then even without gateway you can refresh the data set. so, any data set can be easily refreshed. the fascinating fact is:

You can refresh your data set from an application. Any time you like, at any frequency you like. After ETL run, or on a schedule basis. This is Refreshing data beyond limits.

Refresh History

The new REST API is an evolution in Power BI integration. You can even read the history of refresh for a data set. Here is the code for it:

Running this code will return the whole history of refresh for that data set. You can easily understand the type of refresh, and time and status of each.


Same refresh history in Power BI service:


This means you can easily write an application that refresh the data set anytime, and also check the history of refresh for troubleshooting.

In the next blog post I’ll explain some of other great features of Power BI REST API, such as managing gateways and data sources.

Reza Rad
Reza Rad is an Author, Trainer, Speaker and DW/BI Consultant. He has a BSc in Computer engineering; he has more than 15 years’ experience in databases, programming and development mostly on Microsoft technologies. He is a Microsoft MVP in Data Platform for seven continues years (from 2011 till now) for his dedication in Microsoft BI. He is author of some SQL Server and BI books, and also Power BI online book; from Rookie to Rock Star.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">