Forum Discussion
vacuesta
6 years agoHelper I
How to pass date parameter through MYSQL query
Hi. I need help being able for users to enter a value through a date parameter (ie: 'Previous Month', 'Previous Quarter', 'Year to Date', 'Previous 3 Months', etc). Right now I have the code: ...
- 6 years ago
Hi vacuesta
As tested, it is possible on my side.
I test with SQL Server database, i create code in Advanced editor as below.
let Source = if Parameter1="previous month" then let Source1 = Sql.Database("WS-maggiel-02", "power bi test", [Query="select * from ss where DATEPART(m, [date]) = DATEPART(m, DATEADD(m, -1, getdate()))#(lf)AND DATEPART(yyyy, [date]) = DATEPART(yyyy, DATEADD(m, -1, getdate()))"]) in Source1 else if Parameter1="previous quarter" then let Source2 = Sql.Database("WS-maggiel-02", "power bi test", [Query="select * from ss where DATEPART(q, [date]) = DATEPART(q, DATEADD(q, -1, getdate()))#(lf)AND DATEPART(yyyy, [date]) = DATEPART(yyyy, DATEADD(q, -1, getdate()))"]) in Source2 else let Source3 = Sql.Database("WS-maggiel-02", "power bi test", [Query="select * from ss"]) in Source3 in SourceBest Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
vacuesta
6 years agoHelper I
I have a clarification question. In the code you used this line
Source1 = Sql.Database("WS-maggiel-02"Is this a database that I can access?
Please let me know. Thank you.
v-juanli-msft
6 years agoCommunity Support
Hi vacuesta
This is the server name of my database(SQL Server), you can't access to that.
Please change the connection query with your database(MySQL).
Best Regards
Maggie