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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
kushanNa
Super User
Super User

[Blog Post] Extract Data from a Power BI Semantic Model Using Python (Locally)

Power BI datasets (also known as semantic models) are powerful tools for modeling and analyzing business data. While Power BI Desktop and Service provide robust visual tools, sometimes you need programmatic access to extract data directly from the model using Python—for automation, custom dashboards, or data validation tasks.

 

🧠 Why This Blog?

 

I noticed a growing need among data professionals to extract data from Power BI semantic models directly into Python environments—especially for those who want to integrate Power BI data into external tools, scripts, or automation pipelines.

There are solutions scattered all over the internet, from Microsoft documentation to forums and in discussions. However, these resources are often hard to piece everything together if you're new to the topic.

 

In fact, a recent question raised in the Power BI Community about extracting data using Python directly from a semantic model made me realize how unclear this path still is for many. That question—and the number of partial answers it received—highlighted the need for a clear, complete guide.

So, I decided to write this blog to bring everything into one place: a clean, practical, and working example of how to connect to a Power BI dataset, run DAX queries, and extract data using Python. If you're looking to go beyond the Power BI UI and unlock your dataset with code, this guide is for you.

 

🧰 Requirements

 

  • Install Python library:

pip install adodbapi

 

 

Step 1: Connect to the Power BI Dataset

Start by creating a connection to your Power BI dataset using adodbapi.

import adodbapi

# Connection string to Power BI semantic model
conn = adodbapi.connect(
    "Provider=MSOLAP.8; "
    "Data Source=powerbi://api.powerbi.com/v1.0/myorg/YourWorkspaceName; "
    "Initial Catalog=YourDatasetName"
)
  • Replace YourWorkspaceName with your Power BI workspace name.

  • Replace YourDatasetName with your model name (shown under "Datasets" in Power BI).

 

Step 2: Extract Data 

 

 

cursor = conn.cursor()

# Replace with the actual table name in your data model
dax_query = "EVALUATE 'SalesData'"

cursor.execute(dax_query)

# Print column headers
columns = [col[0] for col in cursor.description]
print("Columns:", columns)

# Print the first 10 rows
rows = cursor.fetchall()
for row in rows[:10]:
    print(row)

cursor.close()
conn.close()

 

Full code

 

import adodbapi

# Connection string to Power BI semantic model
conn = adodbapi.connect(
    "Provider=MSOLAP.8; "
    "Data Source=powerbi://api.powerbi.com/v1.0/myorg/testws; "
    "Initial Catalog=db1"
)

cursor = conn.cursor()

# Replace with the actual table name in your data model
dax_query = "EVALUATE 'SalesData'"

cursor.execute(dax_query)

# Print column headers
columns = [col[0] for col in cursor.description]
print("Columns:", columns)

# Print the first 10 rows
rows = cursor.fetchall()
for row in rows[:10]:
    print(row)

cursor.close()
conn.close()

💡Note: Once you run this code, a Microsoft authentication window will appear.
Log in using the Power BI account that has access to the workspace and dataset.

 

kushanNa_0-1746718313720.png

If everything is set up correctly—authentication, workspace access, and model permissions—you should be able to export data from your desired table without any issues.

kushanNa_1-1746718423999.png

This approach is ideal for automating data pulls, building custom reports, or validating numbers outside of Power BI. By consolidating scattered knowledge into this one guide, I hope this saves you hours of research and gives you a strong foundation for integrating Power BI data into your Python workflows.

 

 

 

 

 

 

1 ACCEPTED SOLUTION
kushanNa
Super User
Super User

As requested by Community Support, marking this as the solution to help other users with similar queries find it more easily 😊

View solution in original post

3 REPLIES 3
kushanNa
Super User
Super User

As requested by Community Support, marking this as the solution to help other users with similar queries find it more easily 😊

v-hashadapu
Community Support
Community Support

Hi @kushanNa Thank you so much for sharing the article on how to extract data from Power BI semantic models directly into Python environments. It was a great reminder of how powerful the Microsoft ecosystem can be when used to its full potential.

Please consider replying with any additional details and marking it "Accept as Solution", as other users with similar queries are more likely to read posts with marked solutions. Thank you.

djurecic
Super User
Super User

Nice article. This should be posted to Fabric Community Blogs though: https://community.fabric.microsoft.com/t5/Fabric-community-blogs/ct-p/fabricblogs

Helpful resources

Announcements
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.

Top Kudoed Authors