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

Join 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.

Reply
elria
Helper II
Helper II

Python Scripts and Power BI

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

5 REPLIES 5
v-deddai1-msft
Community Support
Community Support

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

Hi     

 

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       ,

 

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 

amitchandak
Super User
Super User

@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/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.