Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Problem Statement:
Is it possible to refresh Power BI Semantic Model via Microsoft Fabric Data Pipelines as there is no out of the box connector for Power BI.
Prerequisites:
Solution:
1. Allow Service Principal to access Power BI APIs
We would be leveraging the Power BI REST API : Datasets – Refresh Dataset for refreshing Power BI Semantic Model and Datasets – Get Refresh History for getting refresh status of Power BI Semantic Model.
2. Grant the Service Principal / Organizational Account, Member access on the workspace hosting the Power BI Semantic Model.
Overall flow:
GitHUB code
where we have below parameters defined:
GroupId: This is the Id of the workspace hosting the Semantic Model
SemanticModelId: This represents the Power BI Semantic Model Id
3. Create a new Connection in web activity with Organizational account authentication and appropriate Base Url and Token Audience Uri. Click sign in to proceed.
Base Url: https://api.powerbi.com/v1.0
Token Audience Uri: https://analysis.windows.net/powerbi/api
This blog leverages the option to use a web activity with organizational authentication for an easy refresh of Power BI datasets or semantic models. This method eliminates the need for creating service principals or Azure Active Directory applications.
Service Principal authentication alternative: where provide the appropriate Tenant ID, Service Principal Client ID and Service Principal Key / Secret details.
4. Add Relative URL and Body appropriately for the Trigger Refresh Web activity Settings.
Relative URL: /myorg/groups/@{pipeline().parameters.GroupId}/datasets/@{pipeline().parameters.SemanticModelId}/refreshes
5. The Refresh API call is asynchronous. Hence, we do not know whether the Semantic model refresh has actually succeeded. The successful execution of the web activity does not mean that the refresh was a success. To check the status of the refresh one can leverage Web activity to trigger Power BI Dataset/Semantic Model refresh status via Power BI REST API.
We can leverage the same connection created earlier.
Relative URL: /myorg/groups/@{pipeline().parameters.GroupId}/datasets/@{pipeline().parameters.SemanticModelId}/refreshes?$top=1
6. We must add a polling pattern to periodically check on the status of the refresh until it is complete. We start with an until activity. In the settings of the until loop, we set the expression so that the loop executes until the output of the above web activity is not equal to Unknown because when a Semantic model is refreshing, “Unknown” is the status returned until it completes or fails.
Expression: @not(equals(first(json(string(activity('Get Refresh Details').output)).value).status,'Unknown'))
Within Until Activity:
7. The Final activity is the IF activity that checks the Refresh status and leverages a Fail activity to fail the pipeline in case of refresh failure.
IF Activity Expression: @equals(first(json(string(activity('Get Refresh Details').output)).value).status,'Failed')
Fail Activity Message: @string(json(first(json(string(activity('Get Refresh Details').output))?.value)?.serviceExceptionJson))
Output:
Success:-
Failure:-
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.