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
Solved the issue:
Correct M:
let
Source = Sql.Database("D01PSQLENTA01", "ECI",
[Query="SELECT * #(lf)FROM [NovaDailyEligibilityExtract] #(lf)WHERE PUNBR = '"&UnderwriterSQL&"'#(lf)AND GRNBR = '"&GroupSQL&"'"])
in Source
- smpa016 years ago
Community Champion
great ...GRNBR has probably varchar as the column data type in native DB.
you would normally query in the native DB as
AND GBNBR]='06N'I am glad you managed to adapt it to your solution.