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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.