Power BI Python integration for scripts, steps and visuals
Power BI Python integration lets an author run Python code in three places: as a data source, as a Power Query step and as a visual. Microsoft documents all three for Power BI Desktop. So a team with Python skills can reuse them inside a report. However, each use has rules for refresh and sharing, and those rules decide whether Python belongs in the report at all.
- Scripts as a source
- Python in Power Query
- Refresh rules explained
Last updated
How does Power BI Python integration work in Desktop?
Python must exist on the author's machine first. Power BI Desktop does not ship it, so the author installs Python and points Desktop at that folder. Microsoft's page also names two packages: pandas for data and Matplotlib for charts.
Then the Python script connector runs a script and looks for data frames. Each pandas data frame in the result appears in the navigator as a table. After that, Power BI imports it like any other table.
Power Query offers a second entry point. A Run Python script step receives the current table as a data frame and returns a changed one. For example, a script can fill missing values before the data reaches the model.

Three places Python can run inside a Power BI report
Each place solves a different problem, so we choose one on purpose.
Data source script
The script fetches or builds the data. This helps when no connector fits, but refresh then depends on that script.
Power Query step
The script cleans or reshapes a table mid-query. Still, a native Power Query step is easier to maintain when one exists.
Python visual
The script draws a chart from the fields on the visual. The result is an image, so readers cannot click its marks to cross-filter.
What should a team know before it publishes Python content?
Desktop and the service behave differently. On a desktop, the local Python install runs every script. In the service, however, scripts in the data load need a machine that has Python, because the cloud will not run them alone.
Microsoft's page therefore points to a personal gateway for scheduled refresh. That gateway runs on the machine where Python lives. The article also says the data sources in such a query must use the public privacy level. So a script that touches sensitive data deserves a second look.
Python visuals carry their own conditions. Microsoft documents limits on rows and run time, and it ties support in the service to license type and region. We read the current page with you before anybody builds on them. Forecasts built this way can feed Power BI demand forecasting. To decide whether a task belongs in a report at all, see the Power BI vs Python comparison.
Common faults in a Power BI Python integration
These six issues account for most of the Python problems in reports we review.
- The script works on one laptop only
- Package versions differ between machines
- Refresh depends on a personal gateway
- A script does what Power Query could do
- Visuals time out on large inputs
- Nobody but the author can read the code
Our steps for Power BI Python integration
We work in four stages and demo the report weekly.
Review each script
First we read what the code does and ask whether the report truly needs Python for it.
Agree the plan
Then a written quote states which scripts stay, which move upstream and which become DAX or Power Query.
Rebuild and test
We make the changes in your tenant and test refresh in the service, not only on a desktop.
Document the code
Finally, we note package versions and the gateway setup, so another person can take over.
Questions about Python scripts in Power BI
Can Power BI run Python scripts?
Yes. Power BI Desktop can run Python as a data source, inside Power Query Editor and in Python visuals. Microsoft's Power Query connector list includes a Python script connector. However, Python itself must be present on the machine, along with the pandas and Matplotlib packages. Microsoft's articles describe the setup steps.
Does Power BI Python integration work with scheduled refresh?
It can, with conditions. Microsoft's documentation says a query that contains Python scripts needs a personal gateway on the machine where Python sits. The data source privacy levels must also be public. So we check those two points first. When they are a problem, we move the Python work upstream.
Where should heavy Python work run instead?
Usually before Power BI. For example, a notebook in Microsoft Fabric or a scheduled job can write results to a lakehouse or a database table. Then Power BI reads that table with a standard connector. As a result, refresh no longer depends on one machine, and the model stays simple.
Are Python visuals a good idea for shared reports?
Sometimes. They suit a statistical chart that standard visuals cannot draw. Still, they render as static images and have documented limits. Support in the service also depends on licensing and region. So we use them sparingly and confirm the current rules on Microsoft Learn before a report goes to a wide audience.
Does Power BI Agency write Python scripts?
We review, tidy and relocate Python that feeds reports, and we build the Power BI model around it. One of our consultants leads that work. Power BI Agency is a division of Sataware Technologies and independent of Microsoft. Start with the free 30-minute assessment, or call (480) 485-7373. We answer within 2 hours.
Let's build your first dashboard together.
Tell us what you report on today. A consultant replies within 2 hours with next steps.
Trusted partners
Microsoft Solutions Partner · AWS Partner
Cloud & AI Platforms
Azure SQL, Microsoft Fabric and the data pipelines behind your reports.
AI Business Solutions
Power BI reporting on your Dynamics 365, Business Central and Power Platform data.
Security
Row-level security and Entra ID sign-in on every report and workspace.
Amazon Web Services
Power BI on your AWS data, with connectors for Redshift, Athena and S3.