powerbiazure-sql-databasepowerbi-embeddedpowerbi-datasource

Power BI embedded, direct query, not refreshing


I have implemented Power BI embedded in a web app with direct query using Azure SQL as data source.

The Azure SQL database is being updated by webjobs and if I leave open the Power BI embedded web app I don't see the visuals refreshing with the new data unless I trigger a query for example changing tab or filtering with a slicer. In the documentation I found the following:

"If there is no user interaction in a visualization, like in a dashboard, data is refreshed automatically about every fifteen minutes."

Do I understand correctly that an open visual in my case should be refreshing without need of user interaction?

Can you point out to the reason for it not to be updating automatically? Also do you know a way to control the time of the refresh with direct query without user interaction more exactly than the "...about every fifteen minutes..."

When inspecting the connection properties on Power BI desktop I have made sure it indicates "Direct Query".


Solution

  • From my understanding the embedded report won't refresh automatically. However, if you're using the Power BI JS framework (https://github.com/Microsoft/PowerBI-JavaScript) to embed your report from a Workspace Collection, then you can use a refresh() method on the report object to manually get the latest data, provided your report is using Direct Query.

    This method is only present in version 2.2.0 of the framework and was then removed in the latest version (currently 2.2.1) while further testing around billing is performed (see https://github.com/Microsoft/PowerBI-JavaScript/commit/5230b2f96b10a1104efecdffe78255b9788526b8).

    However, in my testing I found the session count remained unaffected by the refresh method. You can refresh up to intervals of 15 seconds (a limit set by the server). This may change however, given the method was removed in 2.2.1, but using 2.2.0 seems to work currently.

    Here's a quick and dirty example which will refresh the report every minute within the allocated session:

    powerbi.embed(reportContainer, embedConfig);
    report = powerbi.get(reportContainer);
    
    window.setInterval(function () {
         report.refresh();
    }, 60 * 1000);
    

    If the session expires (after 1 hour currently) then a new JWT will need to be requested and the report needs to be reloaded with the new token.

    You may want to implement some checks around the session expiry if you plan to keep the report open for more than the allotted session time.