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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
powerbricco
Advocate I
Advocate I

Pass parameters to SQL query (sql instructions from ODBC)

Dear Forum,

in PowerBI through a ODBC connection i am connecting to a mySql db and the following is my sql query instruction.

powerbricco_3-1769590740828.png

 

What i want is pass parameteres to this sql instruction instead of hardcoding the dates.

Is it possible to do this?

Thank you a lot

 

1 ACCEPTED SOLUTION
v-sgandrathi
Community Support
Community Support

Hi @powerbricco,

 

You can achieve this by using Power Query parameters and incorporating them into your native SQL statement, allowing filtering to occur directly in MySQL rather than within Power BI. This method ensures only the necessary data is retrieved from the source, helping to prevent performance issues that can arise from filtering after import.

To set this up, create parameters in Power BI Desktop by navigating to Transform Data -> Manage Parameters -> New Parameter. For example, you might create StartDate and EndDate parameters with a data type of Date or Date/Time. These will serve as dynamic inputs for your query.

Next, open the Advanced Editor for your ODBC query and update the SQL string to reference these parameters. In Power Query (M), you can insert the parameter values into the SQL statement and format them appropriately for MySQL. When the query runs, Power BI rebuilds the SQL with the current parameter values and sends it to the database.

This approach applies the date filter at the source, so MySQL returns only the relevant data, resulting in faster refresh times and avoiding unnecessary data loads. It is effective for refresh-time filtering in Import mode. For end-user runtime parameters in Power BI Service, DirectQuery or a stored procedure would be required, but for refresh scenarios, this method is recommended.

 

Thank you.

View solution in original post

3 REPLIES 3
v-sgandrathi
Community Support
Community Support

Hi @powerbricco,

 

You can achieve this by using Power Query parameters and incorporating them into your native SQL statement, allowing filtering to occur directly in MySQL rather than within Power BI. This method ensures only the necessary data is retrieved from the source, helping to prevent performance issues that can arise from filtering after import.

To set this up, create parameters in Power BI Desktop by navigating to Transform Data -> Manage Parameters -> New Parameter. For example, you might create StartDate and EndDate parameters with a data type of Date or Date/Time. These will serve as dynamic inputs for your query.

Next, open the Advanced Editor for your ODBC query and update the SQL string to reference these parameters. In Power Query (M), you can insert the parameter values into the SQL statement and format them appropriately for MySQL. When the query runs, Power BI rebuilds the SQL with the current parameter values and sends it to the database.

This approach applies the date filter at the source, so MySQL returns only the relevant data, resulting in faster refresh times and avoiding unnecessary data loads. It is effective for refresh-time filtering in Import mode. For end-user runtime parameters in Power BI Service, DirectQuery or a stored procedure would be required, but for refresh scenarios, this method is recommended.

 

Thank you.

powerbricco
Advocate I
Advocate I

Dear @rohit1991, applying filters after import is terribly slowing the whole process.
You were saying it is possible to use Power Query parameters and reference them in the SQL statement. How is this possible?

Thanks for your help

rohit1991
Super User
Super User

Hii @powerbricco 

 

The supported approach is to use Power Query parameters and reference them in the SQL statement (or apply filters after import). For true runtime parameterized queries, you must use DirectQuery with supported connectors or handle parameters via stored procedures (where supported).


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

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.