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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

4 REPLIES 4
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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