Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
Hello,
How can I use a Parameter (StartYear) in this SQL Statement in Power BI?
Hello,
Yes but what about adding a parameter for the Start Year to load data?
Michael
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.
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!
hi @mikebi ,
reference this: Making data source parameters easy in Power BI Desktop (youtube.com)
let me know if this resolves the issue.