Forum Discussion
Pass date parameter to a SQL function
- 2 years ago
DukeCarey
I created a parameter, called startdate, in your case it is linked to an Excel sheet, it;s fine. Here is the modified code, which should work for as well. Modify the Date format as per your source system.let DateParam = "'" & Date.ToText(StartDate, "yyyy-MM-dd") & "'", Source = Sql.Database(".", "ContosoRetailDW_2019", [Query="SELECT * FROM dbo.GetCustomersByDateFirstPurchase(" & DateParam & ")", CreateNavigationProperties=false]) in Source
DukeCarey
I created a parameter, called startdate, in your case it is linked to an Excel sheet, it;s fine. Here is the modified code, which should work for as well. Modify the Date format as per your source system.
let
DateParam = "'" & Date.ToText(StartDate, "yyyy-MM-dd") & "'",
Source = Sql.Database(".", "ContosoRetailDW_2019", [Query="SELECT * FROM dbo.GetCustomersByDateFirstPurchase(" & DateParam & ")", CreateNavigationProperties=false])
in
Source
Thanks Fowmy, I think we're inching closer now. After mimicking what you posted I ran into the formula.firewall error and I'm stumped there now.
Formula.Firewall: Query 'PivotPurchaseTypesSince' (step 'Source') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.
- DukeCarey2 years agoRegular Visitor
BTW, I tried to "flatten" the query based on a blog post and tried this:
let
SourceX = Excel.CurrentWorkbook(){[Name="StartDate"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type date}}),
Column1 = #"Changed Type"{0}[Column1],
DateParam = "'" & Date.ToText(Column1, "yyyy-MM-dd") & "'",Source = Sql.Database("test.database.windows.net", "testdata", [Query="SELECT * FROM rpt.PivotPurchaseTypesSince(" & DateParam & ")"])
in
Sourcebut then got this error:
Expression.Error: A cyclic reference was encountered during evaluation.