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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
guitardude333
Frequent Visitor

How to add parameters to Python script?

I am running a Python script in Power BI which does some calculations and creates a table 'PythonTable'. This table is then used by a report. Somewhere in the script, this can be found:

 

overall=pd.concat([name,lang,cert],axis=1)

res = (df_multiply_modified(overall, overall.T)).stack().reset_index(level=1)

 

The code is using the variable 'overall' which combines some groups like name, lang cert. I would like to add a slicer which can select for example name and lang, so the script will change to:

 

overall=pd.concat([name,lang],axis=1)

 

And hence 'PythonTable' will be updated. I could also just choose name, so the script will be:

 

overall=pd.concat([name],axis=1)

 

How can I achieve this?

Thank you

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Hello, I have a simpler case, I want to pass a parameter to the Python script that serves as a value of a range, I have created the P parameter as a decimal number (it doesn't leave me integer) and linked to the query/list value I want. In the Current Value box I can't "deploy" anything, it only allows me to put a current value. The problem is that I can't update the parameter value so that it has the query/list value assigned to it.

On the other hand, within the Python script the value 71 of this script fragment should be replaced by the parameter and I imagine it should be: for i in range(71) ---> for i in range(" & P & "):

You can help me with the first point and confirm the second one. Thanks a lot!!.

v-jingzhang
Community Support
Community Support

If you want to pass a query parameter to python script, it is supported.

121703.jpg

I made a simple demo for this, but it's not perfect. When switching to choose a parameter value which contains fewer or different columns, the steps below the Source step will probably report errors as they cannot find the missing columns to transform.

 

So I think dynamically changing the columns with parameters is probably not a good idea. It's suggested to contain all the necessary columns in the model, but select different columns for different visuals as you need in the report.

 

Kindly let me know if this helps.

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

Anonymous
Not applicable

How do you get to that screen?

@Anonymous It is Advanced Editor in Power Query Editor. Query overview in Power BI Desktop 

vjingzhang_0-1658887140557.png

v-jingzhang
Community Support
Community Support

Hi @guitardude333 

 

If I guess correctly, your python table is a table query created by python script, right? If so, it is created first, then loaded into Power BI Desktop to create a report from. If you want to use a slicer in the report to dynamically change the columns in your python table, I'm afraid this is not supported. The slicers and filters in the report are not able to influence how a table query is created and transformed in the Query Editor.

 

Best Regards,
Community Support Team _ Jing Zhang

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.