Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
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.
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
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).
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.
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.
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.
Solved! Go to Solution.
As requested by Community Support, marking this as the solution to help other users with similar queries find it more easily 😊
As requested by Community Support, marking this as the solution to help other users with similar queries find it more easily 😊
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.
Nice article. This should be posted to Fabric Community Blogs though: https://community.fabric.microsoft.com/t5/Fabric-community-blogs/ct-p/fabricblogs
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.