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
Omid_Motamedise
Super User
Super User

How to allow user input for Python scripts in Power BI

I'm trying to create a Power BI report where a Python script generates a table by running in Power Query, but the script requires a user-defined input parameter.

The input range is wide, and the execution time of the Python script is high, and it impossible to run it for all possible ranges.

What is the best way to ask for the input parameter from the user?


If my answer helped solve your issue, please consider marking it as the accepted solution.
1 ACCEPTED SOLUTION
v-sdhruv
Community Support
Community Support

Hi @Omid_Motamedise ,

Python scripts in Power Query run during data refresh, not interactively. So the parameter must be set before refresh.

If the script is too slow for large ranges, consider caching results or preprocessing data outside Power BI.

Another approach could be-

Create a table with possible input values then use a slicer to let users pick a value then  DAX to pass the selected value to a measure or calculated table.


Hope this helps!

 

 

 

View solution in original post

3 REPLIES 3
v-sdhruv
Community Support
Community Support

Hi @Omid_Motamedise ,

Python scripts in Power Query run during data refresh, not interactively. So the parameter must be set before refresh.

If the script is too slow for large ranges, consider caching results or preprocessing data outside Power BI.

Another approach could be-

Create a table with possible input values then use a slicer to let users pick a value then  DAX to pass the selected value to a measure or calculated table.


Hope this helps!

 

 

 

Shahid12523
Community Champion
Community Champion

You can’t use input() in Power BI. Instead:

 

Use Power Query Parameters → create a parameter, pass it into your Python script, refresh with user-defined value.

Or use a Slicer → let users pick a value/range, filter data, then run the Python script only on that subset.

 

👉 Best choice: Parameters for free input, slicers for predefined values.

Shahed Shaikh

@Shahid12523  Thank you for your reply. However, it isn’t an interactive experience for the user, as it still requires going into the Power Query section to change the parameter value, and the slicer also needs to consider all the combinations for the parameter, which in this case is impossible. I’m looking for a more user-friendly, interactive approach.


If my answer helped solve your issue, please consider marking it as the accepted solution.

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.