Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
boyddt_mn
Helper IV
Helper IV

Using Python to Connect to Power BI data model

Hello. I have what seems like should be an easy solution. We have some reports that are already created and published that we want to use Python to create control charts with. Everything I can find on the web - so far - references connections to outside sources. How do I get Python to read the existing data model in Power BI?

2 REPLIES 2
Anonymous
Not applicable

Hi  @boyddt_mn ,

 

 

The following link shares about using Python scripts to import a data source, clean the data, analyze the data and create visualizations with it:

Solved: PYTHON INTEGRATION WITH POWER BI - IMPORTING EXCEL... - Microsoft Fabric Community

 

You can use Python scripts to manipulate existing data. This can be done in the "Transform" tab under the Edit queries section. There is an option to select "Run Python Script". Once you select this option a dialog box will open and you can write the Python script you want.

Use Python in Power BI Power Query Editor - Power BI | Microsoft Learn

 

This is the related document, you can view this content:

pandas - How to read Data From Power BI Dataset to Python - Stack Overflow

Solved: How to read Data From Power BI Dataset to Python - Microsoft Fabric Community

Run Python scripts in Power BI Desktop - Power BI | Microsoft Learn

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your response but these don't three of the five links don't reference connecting to a local data model. The second and third links suggest using dataset to connect to the local model but Power BI returns "NameError: name 'dataset' is not defined". I've tried a couple if iterations but haven't had much luck. Here is my code:

import pandas as pd
import seaborn as sb
import matplotlib.pyplot as plt
CAPA_Main = dataset[dataset["CAPA_Main"]]
plt.bar(CAPA_Main.capa_main.created_date, CAPA_Main.capa_main.cap_number)
plt.xlabel("Date")
plt.ylabel("NR Count")
plt.show

and here is a screenshot of my data model

boyddt_mn_0-1719583648532.png

 

Any help is appreciated.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.