Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Web.Contents with dynamic date query

Hi, I have created the below query to pull data from a large datasource showing only data from last Monday;     let AuthKey = "removed", LimitUsed = Number.ToText(Limit), reportPath = Text....
  • v-jingzhang's avatar
    5 years ago

    Hi Anonymous 

    You can create a list with below codes to get the date of last monday dynamically. I name this query as DateOfLastMonday.

    let
        Source = Date.ToText(Date.From(Date.AddDays(Date.StartOfWeek(DateTime.LocalNow(),Day.Monday),-7)),"dd/MM/yyyy"),
        #"Converted to List" = {Source}
    in
        #"Converted to List"

     

    Then create a query parameter with above list. I name it as Parameter_lastMonday.

    "22/03/2021" meta [IsParameterQuery=true, ExpressionIdentifier=DateOfLastMonday, Type="Text", IsParameterQueryRequired=true]

     

    At last, use the parameter to replace the fixed date string in your original query.

    let
      AuthKey = "removed",
      LimitUsed = Number.ToText(Limit),
      reportPath = Text.Combine({"/datasets/37/feedback?limit=",LimitUsed}),
      Source = Json.Document(Web.Contents("removed", [Headers=[#"content-type"="application/json", #"x-auth-token"=AuthKey], RelativePath = reportPath, Query = [date_from = Parameter_lastMonday]]))

     

    You can refer to this post for how to create the list and parameter.

    Daily data refresh from the same file - Microsoft Power BI Community

     

    Kindly let me know if this helps.
    Community Support Team _ Jing
    If this post helps, please Accept it as the solution to help other members find it.