Power BI on Jupyter Notebook?

 In Analytics, Power BI, Strategy

Okay, let’s get this straight. One of the coolest things about Power BI as a product is its ability to connect to an insane number of data sources. The Power BI development team seems to find new data sources out of thin air and develops, releases them with every monthly update. On the other hand Power BI released an integration this year, which got me excited. Power BI in Jupyter notebook! (Psst! This includes Google Colab as well)

As someone who uses Jupyter Notebook to do a lot of work and even use it for presentations, this was a welcome integration from me. In this blog, we will explore the powerbiclient package using python on Jupyter notebook.

Let’s launch Jupyter notebook on our laptop.

Installing and importing the package

First, to install the package we use pip install. Pip will check base requirements and resolve dependencies to install the package.

Use the below statement:

! pip install powerbiclient

After the package has been successfully installed, we import the package using the below statement.

from powerbiclient import Report, models

We are installing the Report and models module from the powerbiclient package.

After we have installed that, we need to import another class that will help us to authenticate with Power BI

Authentication
from powerbiclient.authentication import DeviceCodeLoginAuthentication
device_auth = DeviceCodeLoginAuthentication()

This will in turn, give us an output similar to the one below.

Power BI on Jupyter Notebook?

Power BI on Jupyter Notebook?

We need to click on that link. A prompt opens up asking for a code. We need to paste the code that is in the output. It will prompt us to login with our Microsoft account.

Once logged in, we return to our notebook and output will say “Interactive authentication successfully completed” .

Getting the group and report ID from online service

Now, we go to the report we intend to embed in the notebook to get the group id and report id.

Power BI on Jupyter Notebook?

Power BI on Jupyter Notebook?

The group ID is at the orange arrow and report id at the white arrow.
We copy that and paste it below.

group_id="***"
report_id="***"

Now, we connect it to the report. We pass the group_id, report_id and device_auth to the report and print the report.

Embedding the report

report = Report(group_id=group_id, report_id=report_id, auth=device_auth)
report

Voila! We get our report in the notebook. It works and feels like a report that is on the online service. We can navigate through pages, we can use the slicers on each page, we can even interact (cross-highlighting) with the visuals. It looks like the one below.

Power BI on Jupyter Notebook?

Power BI on Jupyter Notebook?

Now let’s explore a bit further.

Is there a way to find out all the filters applied to this report?
Yes! We use the get_filters() method to return the filters in a list.

filters = report.get_filters()
filters

Is there a way to remove all the filters from the embedded report?
Yes! We can use the remove_filters() method to remove all of the pre-existing filters on the report.

report.remove_filters()

We can update the filters programmatically too but we can directly do it in the report displayed too.

We can get the list of pages, get the list of bookmarks, get a list of all visuals, apply a bookmark and much more using this package.

More to be found on
https://github.com/microsoft/powerbi-jupyter

So, these are the features that are available from this package. This is a great start to this integration. We have attempted to embed the entire report directly to the notebook. It gives us the look and feel of online service on the notebook itself. I am excited for this to get better in coming iterations (hoping there are).

One feature that would have been great is to let us have the pick of visuals from each page to show instead of the entire report. Another feature that could be added is let us call only certain pages of the report instead of the whole report, thereby reducing time and data.

Hope this article helps.

Recent Posts
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Request For Demo


This will close in 20 seconds

Data Visualisation – How to design charts and graphs