I have the below query which is giving me all kinds of problems. I believe issue has to do with the date and trying to pass the date as a parameter from an excel workbook. The query runds fine when the Month3 name line is removed and a date of '2021-12-31' in place of Month3. I'm a novice, so it maybe more than just a date parameter issue. I attached a snipit of where the date parameter is coming from. The cell name is Month3, cell date 2021-12-31 is a text format. Any help to solve, or steer me in the right direction would be greatly appreciated.
let
Source = Sql.Database("sm-sqldev.public.97600fbb54a7.database.windows.net,3342", "DM_Finance", [Query="use DM_Finance
Month3 = Excel.CurrentWorkbook(){[Name=Month3]}[Content]{0}[Column1]
declare @apl as Date = Month3
SELECT distinct
GL.CycleDate
, LI.PropertyAlphaStateCode
, GL.GlkDimension1ProductCode
, count(GL.LoanNumber)
, sum(GL.FirstPrincipalBalance)
FROM MspData.GlDimensionsForDate(@apl ) AS GL
INNER JOIN MspData.LoanInfo AS LI ON LI.LoanNumber = GL.LoanNumber
left join [DM_Finance].[DataImport].[InvestorMatrix] AS IM on IM.Investor = GL.InvestorId
where
GL.FirstPrincipalBalance <> '0.00'
and GL.InvestorId <> 'SM1'
and HiType <> '2'
group by
GL.CycleDate
, LI.PropertyAlphaStateCode
, GL.GlkDimension1ProductCode"])
in
Source