Hello guys, today I will explain to you how to create visual reports in python using power BI step by step with the installation. So, have patience and read this blog till the end, I hope you will enjoy and learn from this one. You might have the basic knowledge of python, here I am not going into the deep explanation of this. Python is the world’s most popular language and it can be used in various applications that are mentioned below.

  1. Machine Learning
  2. Web Development
  3. Data analysis and data visualization
  4. System Application Development
  5. Game Development
  6. API Development

In this blog, I will figure out how we can use Python for Power BI using content Visual. Microsoft Power BI released Python content visuals in the August 2018. There are two editors settings through which we can write our own code.

  1. Explore Python for Power BI
  2. Explore Python IDE (Visual Studio Code) in Power BI

Here, I will discuss the implementation procedure of Python for Power BI.

The Power BI has added a feature to the run Python scripts easily in Power BI Desktop. For creating your data model and reports visualization, you need to integrate Python, perform data cleaning, perform advanced data shaping and analytics in your datasets. After that, you need to find out the missing data. Now, you can use Python to create new visuals on your report. Just like using R visuals, the Python visuals is updated with data refreshes and cross-filtering also.

Step 1

First, you have to check and make sure if PYTHON Support feature is enabled in power bi desktop application or not. If you do not know, then follow steps to enable this setting. For this setting, go to file menu in power BI desktop, click on option and setting, after that select options from these settings as showing in this below image.

After clicking on option as showing in highlighted No.3 then a new pop-up will open with more settings on the left side, you have ‘click on preview features’ then check all settings. If you want to know more then click on ‘learn more’ button. The checkbox on ‘python support’ should be checked and click on OK. Follow my serial no as shown in image click first step then second and so on.

Step 2

If python is not installed on your system then you should install python. For that, you need to go to the python official website and install python according to your system(OS) configuration:

Download link here https://www.python.org/downloads

Step 3

After you download, Click install now.

Step 4

It will show the set-up progress as given in the image.

Step 5

When it’s installed successfully with no error, then it will show the installation message installed successfully.

Step 6

The important step is to set the path of installed Python setup from Python scripting option. Let me explain it how we can do that.

  1. Go to the File menu section, from ‘Options and Settings’ then select Options.
  2. From Python Scripting which is showing on the left side of menu items, check the path for “Detected python home directories” this is the path of python installed location. This will take path automatically. If the path is not set up automatically, then set it manually.

For now, Python is effectively introduced on your machine. We should introduce IDE for Python scripting. Here, you should install Visual Studio Code as an IDE for the Python.
After Successfully installation, you need to restart your Power BI dashboard application, then open again dashboard and click on ‘get data’> ‘other option’> ‘python script’ option.

After validation of connection & all settings, then one another window will open. This is power BI desktop python editor. Here, you can write the python script. If you do not have any python script then I am providing simple bar graph code in python script for demo purpose. You just need to copy this code and paste it in your python editor and click on ok button. Power BI python will compile and validate code then visualize the results on the selected graph like bar, pie charts etc.

Now, follow as showing in the below image. First, just click on the graph from the visualization section. Here, I am just selecting the bar chart for demo purpose. You can select any chart according to your data. Data should be the valid otherwise graph will not be drawn in the dashboard so you have to take care of your valid data.

Now just click on the highlighted point 2, which is showing on the visualization section. This will open python editor.

Firstly, you should need to install required python library matplotlib and numpy in your system. matplotlib is used for visualizing graph, and numpy library is used for numerical calculation.

If you do not install these libraries in python then follow the below steps otherwise skip.

Go to system start menu> search python> click on it> python console. Then, just copy and enter the below two commands one by one.

1. pip install matplotlib

2. pip install numpy

Now you need to copy and paste the below code in python editor and click on ok, it will show a graph.

import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

objects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
y_pos = np.arange(len(objects))
performance = [10,8,6,4,2,1]

plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.title('Programming language usage')



In this article, I have first explained to you how to install python in your local machine then I explained to you how to integrate python code into Power BI Desktop. The libraries which you are going to use in power BI desktop must be installed in your python folder libraries like numpy and matplotlib. If you have any query regarding this blog or facing any issues you can post your queries in the comment section below. Thanks!



Please enter your comment!
Please enter your name here