Embed Power BI Reports In Jupyter Notebooks

  • Published
  • Posted in Power BI
  • Updated
  • 2 mins read
  • Tagged as

Recently Microsoft has added a new feature that allows you to embed your reports right into your jupyter notebook cells. This new highlight lets you embed your reports, dashboards, report visuals, Q&A visuals in jupyter notebooks for in-depth exploration.

Before embedding your reports in Jupyter notebooks, create your Power BI reports and then publish them to the Power BI service.

Once the reports are prepared and published then comes the embedding part. The embedding can be achieved with the new python package – Power BI client. You can install this open-source python package from PyPI or just execute the following command in the command prompt.

Pip install Power BI client

Now we will switch to jupyter notebooks.

  1.  From the recently installed package import report and models.

# import required packages
from Power BI client import Report, modelsAuthenticate yourself against Power BI

2. Authenticate yourself against Power BI against Azure.

# Import the DeviceCodeLoginAuthentication class to authenticate against Power BI
from powerbiclient.authentication import DeviceCodeLoginAuthentication

# Initiate device authentication
device_auth = DeviceCodeLoginAuthentication()

Once you execute the above code, you will be asked to authenticate yourself. To sign in, go to this URL – https://microsoft.com/devicelogin and enter the given code to authenticate.

3. Fetch the workspace id and the report id from the Power BI service. If you open your report in the Power BI service you can find these values in the web URL of your report.

# fetch the variables
group_id = “# enter your workspace ID here”
report_id = “# enter your report ID here”

4. Create a power bi instance and load the report in the notebook cell.

# create the report instance
report = Report(group_id=group_id, report_id=report_id, auth=device_auth)
# report output
report

Addend Analytics is a Microsoft Gold Partner based in Mumbai, India, and a branch office in the U.S.

Addend has successfully implemented 100+ Microsoft Power BI and Business Central projects for 100+ clients across sectors like Financial Services, Banking, Insurance, Retail, Sales, Manufacturing, Real estate, Logistics, and Healthcare in countries like the US, Europe, Switzerland, and Australia.

Get a free consultation now by emailing us or contacting us.