Short answer: a Python visual or R visual runs a script on the fields you give it and shows the picture the script draws. The fields arrive as a dataframe called dataset, grouped like a table visual (duplicate rows appear once unless you add an index). Use them for charts Power BI does not have: a box plot, a regression with confidence bands, a correlation matrix. They are images: no hover, no click to cross-filter. The limits are 150,000 rows, 72 DPI and five minutes; in the service only supported packages run.
A violin plot of delivery times per carrier, or a correlation heatmap of twenty measures, are three lines of seaborn or ggplot2. In Power BI they are a script visual, and they still react to slicers.
What does a script visual do?
- 1Fieldsthe columns and measures dragged into the visual
- 2dataseta pandas or R data frame, grouped, duplicates removed
- 3Scriptyour Python or R code draws a plot
- 4ImagePower BI shows the plot; filters re-run the script
How do you make one?
- In Power BI Desktop, set the Python or R installation in Options, Python scripting or R scripting. Install the packages you need (pandas and matplotlib for Python).
- Select Python visual (or R visual) in Visualizations and enable script visuals when asked.
- Drag fields into Values. The editor shows the generated code that builds
dataset. - Write the script under it and run it.
A box plot of delivery days by carrier in Python:
import matplotlib.pyplot as plt
dataset.boxplot(column="Delivery Days", by="Carrier", grid=False)
plt.suptitle("")
plt.title("Delivery days by carrier")
plt.ylabel("Days")
plt.show()The same in R with ggplot2:
library(ggplot2)
ggplot(dataset, aes(x = Carrier, y = `Delivery Days`)) +
geom_boxplot() +
labs(title = "Delivery days by carrier", y = "Days")Because fields are grouped, two orders with the same carrier and the same delivery days become one row. Add Orders[Order ID] to the fields so every order is a row.
What are the limits?
Microsoft lists for both languages:
- 150,000 rows: more are cut to the top 150,000 and a message appears on the image.
- 72 DPI: the picture is a raster image at 72 DPI.
- Five minutes: a longer calculation times out with an error.
- Service packages: Power BI Desktop uses any package you install; the service runs only supported packages (for R, open-source packages from CRAN; no private packages).
- Licensing: viewing script visuals in the service needs a Pro or Premium Per User license, or a workspace on a Fabric capacity; script visuals in the service work in Fabric regions.
- Interaction: a script visual is filtered by others but cannot filter them.
When is something else better?
| Need | Better choice |
|---|---|
| A chart Power BI has (bar, line, scatter) | the built-in visual: interactive, fast, themeable |
| A common statistical chart (box plot, violin) | a certified custom visual from AppSource |
| A one-off analysis with a special library | Python or R visual, or a Fabric notebook |
| Results needed as numbers in other visuals | compute them in Power Query or a notebook, not in a visual |
What goes wrong?
- Grouped rows. Statistics on deduplicated data are wrong; add a unique ID field.
- A package missing in the service. The visual works in Desktop and shows an error after publishing; use supported packages.
- Slow pages. Each script runs on every filter change; keep data small and scripts fast.
- Expecting interactivity. No tooltips, no selection; put a table next to it for details.
Where can you check this?
- Microsoft Learn: Create Power BI visuals with Python
- Microsoft Learn: Create Power BI visuals by using R
- Microsoft Learn: Create and use R visuals in Power BI
Where do you start?
Use a script visual for the one chart Power BI cannot draw, add a unique ID field so no rows are merged, and check the packages are supported in the service before you publish. Custom visuals are the interactive alternative for common special charts.