Forum Discussion
Include Parameters within Power BI to Query a SQL Data Source
- 6 years ago
Anonymous
let's suppose your
server = x
database = y
table name = z
sample sql query is (as you would put it on SSMS)
select *
from z
WHERE [period_number]=2
AND [fiscal_year]=2020when you put this on a M
it becomes this
let Source = Sql.Database("x", "y", [Query="select *#(lf)from zs#(lf)WHERE [period_number]=2#(lf)AND [fiscal_year]=2020"]) in SourceNow if you want to pass two parameters to the where clauses as P1 and P2, (P1=2020, P2=2)make sure they are text first
you can create a custom query as below
(x as text, y as text)=>let Source = Sql.Database("x", "y", [Query="select *#(lf)from z#(lf)WHERE [period_number]="&P2&"#(lf)AND [fiscal_year]="&P1&""]) in Source
The simplest way to do this is to use the UI to filter the your fields and select any single value. The resulting Filter step can then easily be edited, where you replace the string of the single value you selected with your parameter. The step would look something like if you use the UI to filter a field.
Table.SelectRows(dbo_NovaDailyEligibilityExtract, each [PUNBR] = "123" )
And you would alter it to
Table.SelectRows(dbo_NovaDailyEligibilityExtract, each [PUNBR] = #"Underwriter #(#)(SQL) (201)")
Power Query will convert this into SQL statements on the backend, you can right click on the step and click "View Native Query" to see this.
I don't know what you mean by "use the UI to filter". I googled it and I've gone in to settings and "Enabled it.":
Do you mean to simply go in to Edit Query and add a step where I filter for the two criterias I need?
I do not know what the 'UI' is you are referring to??