Using the Python Visualization for Power BI

Leave a comment

In our previous posts, we installed and set up Python for Power BI and used Python as a datasource in a Power BI Desktop report. We also used Python to filter data in Power Query. In this post, we will look at the Power BI Python Visualization.

In Power BI Desktop, select the Python visualization:

You may see the message below. Click Enable:

We will add a couple of fields from our dataset, AccountName and Revenue to Values:

We can see the following Python code is already added:

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
# dataset = pandas.DataFrame(AccountName, Revenue)
# dataset = dataset.drop_duplicates()
# Paste or type your script code here:
Let’s add to this code. We will display a bar chart using matplotlib. We have 2 fields in our data, Account Name and Revenue that we will display:

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset = pandas.DataFrame(AccountName, Revenue)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import matplotlib.pyplot as plt

plt.xlabel(‘Account Name’)
plt.xticks(rotation=’vertical’)
plt.ylabel(‘Revenue’)
plt.title(‘Account Name vs Revenue’)

plt.bar(dataset.AccountName, dataset.Revenue)
plt.show()

This displays our chart in Power BI. Note we are using plt.xticks(rotation=’vertical’) to display the x-axis fields vertically, otherwise they will bunch together:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *