2

I have seen the reference posts on SO here and here. I have tried the responses from the forums but can not successfully run my PowerQuery.

So far I have named both my Start and End date cells as "StartDate" and "EndDate". From there I have created two blank queries, both renamed to StartDateValue and EndDateValue and look like this: (StartDate) => Excel.CurrentWorkbook(){[Name=StartDate]}[Content]{0}[Column1] and (EndDate) => Excel.CurrentWorkbook(){[Name=EndDate]}[Content]{0}[Column1]

Now, Looping back to my original PowerQuery, the where clause to set these date parameters looks as such:

 AND A."CREATED_DTM" BETWEEN Excel.Workbook(File.Contents(StartDateValue("StartDate"))) and Excel.Workbook(File.Contents(EndDateValue("EndDate")))
          

Doing so doesnt seem to work. Though if I replace my "failed" call and simply input date values like '5/1/2022' my script executes normally. Maybe I am missing a step or not calling the values properly in my SQL...not too sure. Any information on this helps, thanks.

cgwoz
  • 253
  • 1
  • 12

1 Answers1

0

I'm not sure how you plan to use it in powerquery, but you likely want the contents of the StartDate and EndDate cell in text format within the query, so ditch your two functions and just include these rows in your code

SD = Text.From(Date.From(Excel.CurrentWorkbook(){[Name="StartDate"]}[Content]{0}[Column1])),
ED = Text.From(Date.From(Excel.CurrentWorkbook(){[Name="EndDate"]}[Content]{0}[Column1])),

then you can use SD and ED as necessary

text = "this is some text with " & SD & " and " & ED & " in them"

= Sql.Database("SERVER", "DATABASE", [Query="SELECT * FROM [TABLE] WHERE weekStartDate>='"&SD&"'"])
horseyride
  • 17,007
  • 2
  • 11
  • 22
  • I just want to passthrough the date values in my 2 cells into my ODBC SQL Script as a date parameter in my WHERE clause. Example: WHERE Date between '4-1-2022' and '5-1'2022' But my two dates are my cell values – cgwoz May 25 '22 at 13:22