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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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.

djurecicK2
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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Kudoed Authors