Share via

Power Query using parameters (fnGetParameter) only works with one parameter

Anonymous
2017-09-30T16:17:48+00:00

I have the following Power Query:

let

    WeekBegin = Text.From(fnGetParameter("WeekBegin")),

    WeekEnd = Date.From(fnGetParameter("WeekEnd")),

    Source = Odbc.Query("dsn=RCT Development", "SELECT wo.id, wo.last, wo.servicelocation, resit.resourcesched, resit.resourcehours FROM workorders wo INNER JOIN (SELECT * FROM resourceitems) resit WHERE ((wonumber = wo.id) AND (resourcesched BETWEEN '"&WeekBegin&"' AND '"&WeekEnd&"')) ORDER BY wo.servicelocation"),

    #"Grouped Rows" = Table.Group(Source, {"servicelocation"}, {{"Total Hours", each List.Sum([resourcehours]), type number}})

in

    #"Grouped Rows"

I have a table defined in a worksheet with my parameters table and values for WeekBegin and WeekEnd.

The problem is that the query returns 0 rows if I user WeekEnd.  If I hard code the value as '2017-09-30', the query works as it should.  The value for WeekBegin works fine.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2017-10-01T17:25:09+00:00

    Well after MANY hours of research and trying countless different things, I finally figured it out.

    The cell format for the date in the parameter table (and Excel's presentation of that date to Power Query) was not compatible with the query I was trying to perform with MySQL. 

    I hope someone might benefit from my post some day...

    Here's my working version:

    let

        Start = Text.From(fnGetParameter("WeekBegin")),

        End = Text.From(fnGetParameter("WeekEnd")),

        Source = Odbc.Query("dsn=RCT Development", "SELECT wo.id, wo.last, wo.servicelocation, resit.resourcesched, resit.resourcehours FROM workorders wo INNER JOIN (SELECT * FROM resourceitems) resit WHERE wonumber = wo.id AND (resourcesched BETWEEN '"&Start&"' AND '"&End&"') ORDER BY wo.servicelocation"),

        #"Grouped Rows" = Table.Group(Source, {"servicelocation"}, {{"Total Hours", each List.Sum([resourcehours]), type number}})

    in

        #"Grouped Rows"

    Was this answer helpful?

    5 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-09-30T16:19:04+00:00

    The code I posted shows the WeekEnd as a "Date" type,  but it also fails if I set it as a "Text" type.

    Was this answer helpful?

    0 comments No comments