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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
Memorable Member
Memorable Member

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.