Power BI and Python

No, it’s not about „Monty Python’s Flying Circus“, it’s about another „Python“, a programming language that has recently become part of the Power BI Desktop platform and allows creation of user-defined visuals. Do you really need to use Python? Well, really not! But you must admit that it is convenient, if you are familiar with this programming language, to get the opportunity to “raise a hood” and create visuals according to your own standards …

Let’s see how this works! First, let’s turn on Python in Power BI Desktop. Click on the File tab, and then select the Options and Settings, and further click on Options. Enter Preview Features menu, and turn on the Python support option. After you restart Power BI Desktop, you will see that a new visual in a list with an icon that resembles letters „Py“.

Then, in order to make all of this work, you need to install Python. For this purpose, you need to visit the https://www.python.org/downloads/ link and download the latest version of the installation. The installation process is very simple, you run the downloaded installation file and follow the process … Similar to when installing any Windows application. Note: When starting the installation process, it is important to select “Add Python to PATH” option in the window.

Once the installation is complete, it is necessary to add mathematical library files. Enter Windows Command Prompt and type in the following commands in the console:

py -m pip install pandas
py -m pip install matplotlib

Python will automatically connect to the link, download the corresponding files and make the necessary settings.

You can add a new visual by clicking on the “Py” icon. In the Values ​​box, drag the dimensions you want to use in the chart, for example, CLASSIFICATION and QTY. When you select Python visual at the bottom of the screen, a menu will appear showing the code written in this programming language, based on which you want to create a report. In this example, we introduce a simple program for creating a column chart based on the given dimensions:

import matplotlib.pyplot as plt
x = dataset. CLASSIFICATION
y = dataset.QTY
plt.bar (x, y)
plt.show ()

By clicking on the icon that resembles the PLAY button at the top of the menu, you start the program and modify visual. If everything is done properly you’ll get a simple column chart.

Python has many libraries for plotting complex charts. You can download them on the Internet, and there are detailed instructions for working with them. So if you are willing to write the code and enrich your Power BI reports – get down on it!