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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
carlpaul153
Helper I
Helper I

Is it possible to pass a parameter to a python script?

I have a parameter called "File" and the follow Python script:

 

# 'dataset' holds the input data for this script
import pandas
data = pandas.DataFrame(dataset)
data.to_csv('C:/Users/MyName/Desktop/'"&File&"'.csv')

 

I have based my solution on this post, but it doesn't work.

What am I doing wrong? How can I get the script to save the file with the parameter name?

 
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

I assume you are doing this as part of your query (instead of through a Python visual, in which your parameter wouldn't get passed).  Does it work with you hard code in a file name?  If that is working, I would edit the M code in the Advanced Editor instead of in the pop-up window.  There you should be able to replace the hard-coded filename with "&File&"  (I assume the whole Python code is surrounded in double quotes in Advanced Editor and this will break it apart and insert in your paramter value.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

I assume you are doing this as part of your query (instead of through a Python visual, in which your parameter wouldn't get passed).  Does it work with you hard code in a file name?  If that is working, I would edit the M code in the Advanced Editor instead of in the pop-up window.  There you should be able to replace the hard-coded filename with "&File&"  (I assume the whole Python code is surrounded in double quotes in Advanced Editor and this will break it apart and insert in your paramter value.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


You are completely right @mahoneypat ! thank you very much!!!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.