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
Anonymous
Not applicable

Parameterized SQL Query

Hello, 

 

Is there a way wherein we can have paramterized SQL queries? Baiscally a way to run the SQL query for a specific filter condition rather than the running it for the entire population? 

For example: Let's say I have employees table, instead of importing the entire employees data (SELECT * FROM EMPLOYEES) can I only import the data for a specific employee based on its Employee_ID entered by the user (via slicer or any kind of prompt filter)? So that the SQL would run only for that specific Employee_ID ( SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID = 'XYZ') and take less time to execute. 


Thanks, 
Jash.

1 ACCEPTED SOLUTION
edhans
Community Champion
Community Champion

Yes. Have you seen this article? Your query in Power Query can use this parameter, you just have to ensure that all steps up to and including the point where it filters is "folded" meaning Power Query or the service will generate the SQL statement and just get back the requested data.

 

You can also do this using quries in Power Query that return a single value (text, number, integer, date, etc) and use that query result as a filter. For example, the following query would return the earliest date from a table.

 

let
    Source = #"qryOpen Apply To Nos",
    #"Calculated Minimum" = List.Min(Source, [Date])
in
    #"Calculated Minimum"

 As long as that step folds you could use that query as a filter for your table to only get dates  on or after the date that query calculated. That isn't technically a parameter as defined by Power BI, but it is fully dynamic vs true Parmeters which have to be keyed in in the service.

 

This article has a much fuller description of how I create dynamic date tables based on the earliest and latest dates in my data by using these pseudo-parameters, and in SQL, it is 100% folded the way I do it, so the server does all of the heavy lifting.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Community Champion
Community Champion

Yes. Have you seen this article? Your query in Power Query can use this parameter, you just have to ensure that all steps up to and including the point where it filters is "folded" meaning Power Query or the service will generate the SQL statement and just get back the requested data.

 

You can also do this using quries in Power Query that return a single value (text, number, integer, date, etc) and use that query result as a filter. For example, the following query would return the earliest date from a table.

 

let
    Source = #"qryOpen Apply To Nos",
    #"Calculated Minimum" = List.Min(Source, [Date])
in
    #"Calculated Minimum"

 As long as that step folds you could use that query as a filter for your table to only get dates  on or after the date that query calculated. That isn't technically a parameter as defined by Power BI, but it is fully dynamic vs true Parmeters which have to be keyed in in the service.

 

This article has a much fuller description of how I create dynamic date tables based on the earliest and latest dates in my data by using these pseudo-parameters, and in SQL, it is 100% folded the way I do it, so the server does all of the heavy lifting.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.