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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Dunner2020
Post Prodigy
Post Prodigy

Running python script in power BI

Hi there,

 

I have a script that performs some calculations (do normalization) in python. The output of the script is in the data frame. I want to run that script in Power BI in such a way that whenever new data comes into the tables of power BI, the script runs. I have two issues:

  1. I am not sure where (either in Python visualization or somewhere) to run the Python script.
  2. The script should take input data from the tables present in the dataflow of power BI. I did not come across any information about how to take the data from the table of the data flow present using Python script in Power BI

Any help would be really appreciated.

7 REPLIES 7
v-diye-msft
Community Support
Community Support

Hi @Dunner2020 

 

If the above posts help, please kindly mark it as a answer to help others find it more quickly. thanks!

If not, please kindly elaborate more.

 

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Anonymous
Not applicable

Hi @Dunner2020 

There is a Python visual you can use which is in the Visualizations section.

1. The pyton script will run only when the report page containing it is open not before that.

2. PFB the code to take the data from tables.

 
test <- data.frame(text = dataset$table_name)

@Anonymous @Greg_Deckler ,

Here is a table as shown below:

 

table1.jpg

 

Now I want to run my Python scripts when report loads/runs that perform calculation after reading data from an above mentioned table and save the results into a new table.  My question is how can we read the data from the above-mentioned table using Python code.  @Anonymous I tried your code, but it looks like a R code. I tried to convert into Python but it did not work

 

@Dunner2020 - Right click the query that creates that table and choose "Reference". Now in this new query, insert a Python step into your query. 

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-in-query-editor

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@Dunner2020 - You have 2 options

  1. Run a Python script as part of a query (a step)
  2. Run a Python script to generate a visualization

Which option is correct or whether either will work is not immediately apparent. You might wish to provide more detail.

 

If you go with the 1st option, go into Power Query Editor, Transform tab, look all the way to the right, the last option in the ribbon is "Run Python script". No clue if this works for dataflows actually.

 

Another consideration, don't use Python.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@amitchandak , I want to take data as an input in my Python script from the tables present in the data flow model of power BI.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.