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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
mikebi
Helper III
Helper III

Using a Parameter in a SQL Statement

Hello,

 

How can I use a Parameter (StartYear) in this SQL Statement in Power BI?

 

mikebi_0-1712268088102.png

 

3 REPLIES 3
mikebi
Helper III
Helper III

Hello,

 

Yes but what about adding a parameter for the Start Year to load data?

 

Michael

Anonymous
Not applicable

Hi @mikebi ,

 

Thanks for the reply from adudani , please allow me to provide another insight:

 

When writing your SQL query within Power BI, you cannot directly embed Power BI parameters into the SQL code.

 

You can use Power Query Editor to dynamically generate your SQL query string based on the parameter value.

 

In Power Query Editor, select Advanced Editor.

vhuijieymsft_0-1712284725335.png

 

Enter content similar to the following in the page that opens.

let
    ParameterHere = Number.ToText( #"StartYear Parameter"[Value] ),
    SqlQuery = "SELECT * FROM YourTable WHERE Year >= " & ParameterHere,
    Source = Sql.Database("YourServer", "YourDatabase", [Query=SqlQuery])
in
    Source

 

Replace "YourTable", "YourServer", and "YourDatabase" with your actual table name, server, and database names.

 

Just refresh it after setting it up.

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

adudani
Super User
Super User

hi @mikebi ,

 

reference this: Making data source parameters easy in Power BI Desktop (youtube.com)

 

let me know if this resolves the issue.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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