Wednesday, April 06, 2016

Power BI embedded step by step

Hi All,

In this blog post i am providing a walk through on how to use Power BI Embedded feature in an asp.net MVC application. Microsoft announced this feature in Build 2016 few days ago.
As of now, Power BI embedded feature is still in preview.

This blog post is describing how to build this app from scratch in a step by step. The source code is in GitHub as well.

Power BI Embedded allows developers to integrate Power BI capabilities in their web or mobile application with out the need to login! so customers can view your power bi reports in custom applications without the need to login or provide o365 credentials to view these reports.

To be able to use Power BI embedded you need the following:
1) A power bi report that you have created & saved in (pbix) file format.
2) Azure subscription because we need to provision Power BI workspace collection that will host our reports.
3) An application to integrate these reports to,
a) We will create ASP.NET MVC application to visualize a reports (Step #3)
b) We will create ASP.NET Web Forms application to visualize a report (Step #4)

Open the solution in VS 2015 and set "Provision Sample" project as a startup project.
Follow these instructions to import pbix file into Azure Power BI Workspace collection.

First, we will enter "5" so we create a workspace in an existing workspace collection we have just created in step #1.

Enter Workspace Collection Name: Demo1 (Same name as we created in step #1)
Access Key: From Azure Portal, Copy Access Key (Key1) for the created Workspace collection.
Copy the generated Workspace Id, since we will use it in the next step.

Second, we will enter "6" to import pbix into the workspace we just created in the previous step.

Enter workspace collection name: Demo1
Workspace Id: copy what we have created in the previous step, also, you can get workspace if you refresh azure portal.
File Path: full file path for pbix file.

Now, we have imported our report into Power BI workspace collection that we created in Azure.

I have created a video for step #2 (Optional to watch)

3) Create ASP.NET MVC Application to use PowerBI Embedded reports:
I have checked in the code for this sample, here is what you need to know about this application.
Open Home Controller, Check Index action:

One Pro Tip: you need to make sure to include powerbi.js in any page or the masterpage (aka _layout.cshtml) to be able to show any power bi report in your page. This JS file has been added when i added powerbi nuget packages to my project.

Open the web.config and change these keys as you have in your Azure provision keys before running the application: