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
skai
Frequent Visitor

Binding parameters to python script

hello, I have two PQ datetime parameters: starttime and endtime.
these are passed into a python script that i have writtern into PQ here is part of the M query: start_time = """&Text.From(starttime)&"""#(lf)end_time = """&Text.From(endtime)&""".

this is working as intended, however i would like to make it more dynamic and bind the PQ parameters to a datetable: Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn
I have tried recreating this but i do not have the "Bind Parameter" option under the "Advanced" section. I have seen some posts related to direct query, does bind parameter only work with direct query (is DQ not supported for python?)

Any help would be appreciated

4 REPLIES 4
skai
Frequent Visitor

Hello, @johnbasha33 @thanks for the reply but I have already done this. I was looking for a work around to make passing the start and endtimes more dynami

Don't use Python then.

skai
Frequent Visitor

Brilliant idea

johnbasha33
Super User
Super User

@skai 

The "Bind Parameter" option in Power BI Desktop's Power Query Editor is primarily used with DirectQuery connections to databases such as SQL Server, Azure SQL Database, or Analysis Services. It allows you to dynamically bind Power Query parameters to query parameters defined in your data source.

Unfortunately, the "Bind Parameter" option is not available for Python scripts or other data sources accessed through custom connectors in Power BI Desktop. Custom connectors typically do not support direct parameter binding in the same way as DirectQuery connections to databases.

However, you can achieve similar functionality by dynamically generating the Python script within Power Query using Power BI parameters. Here's an example of how you could modify your Power Query M code to achieve this:

```m
let
// Retrieve parameter values
starttime = #datetime(2022, 1, 1, 0, 0, 0),
endtime = #datetime(2022, 12, 31, 23, 59, 59),

// Convert parameter values to text
start_time_text = Text.From(starttime),
end_time_text = Text.From(endtime),

// Dynamic generation of Python script
python_script = "start_time = """ & start_time_text & """\nend_time = """ & end_time_text & """\n
# Your Python script here",

// Execute Python script
result = Python.Execute(python_script)
in
result
```

In this example, `starttime` and `endtime` are Power BI parameters defined in the "Manage Parameters" dialog. These parameters are then converted to text using `Text.From()`, and the Python script is dynamically generated by concatenating these text values into the script string.

This approach allows you to pass Power BI parameter values dynamically to your Python script within Power Query. However, it does not involve the "Bind Parameter" option, as it's not applicable to custom connectors like Python scripts.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

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.