Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
Hi all,
I would like to combine Power BI with Python scripts and I have couple of questions.
1. My Python scripts currently load data from database (or file) and contains some functions for calculations that returns objects and plots. How I can use these scripts and at what extent?
I noticed that there are two locations for inserting python scripts. The one is via "Get Data">Other>Python scripting and the other is via the vizualization part with the Python editor. Can you please explain what is the difference between the functionalities and for which purpose I should use each of this?
2. I also tried to load the data in power BI directly via the SQL connection and then add my code in the Python script editor, but i get an error that the visual cant be displayed.
The code I use for showing the graphs is the below: Please note that the arguement for the results is items from dictionary. Is it possible to print objects as vizuals in Power BI?
results['plot binomial'].savefig('plot1.png')
results['plot poisson'].savefig('test2.png')
results['plot gini'].savefig('test3.png', dpi=50) # dpi=50 to get the image shrank to 50% of its size
plt.pyplot.show()
Many thanks in advance,
Elria
Hi @elria,
Microsoft provides detailed documentation for you to use python in power bi. You can run python scripts by Get Data -> Python script or in query editor.
Please refer to https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts
Best Regards,
Dedmon Dai
Thank you for your reply. In the end I managed to run python scripts and get visuals but they are not available on Service.
How can i share the python scripts and the python based visuals with my colleagues as well?
Since they run from my local environment, when I publish the report on Service the visualization is not displayed and I get an error "Python visualization is displayed in your organization".
Can I also retrieve the code from GIT/Azure Repo instead of maluanlly copy paste in the power bi editor?
Thank you,
Elria
Hi @elria ,
There are some limits for python visual in Power BI service. Please refer to https://powerbi.microsoft.com/en-us/blog/python-visualizations-in-power-bi-service/
Best Regards,
Dedmon Dai
HI v-deddai1-msft ,
Thank you for your reply. I checked the limitations and I decreased my dataset to 1500 rows but still it doesnt work. The execution time also seems to be short.
Could you please let me know how I could check if I violate any of the other limitations? The error received is quite vague to figure out what is wrong.
Thank you,
Elria
@elria , I am not an expert on this. But refer if this can help
https://towardsdatascience.com/using-python-in-power-bi-ee95a6b71443
https://www.sqlshack.com/power-bi-desktop-and-python-like-peanut-butter-and-chocolate/
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 76 | |
| 38 | |
| 31 | |
| 27 | |
| 26 |