Forum Discussion
Power Query - Dynamic URL Parameters - Coded but not finished
I have a problem using Power query to create part of an URL which holds Date, which must be today and yesterday made into urlencoded and added to the main url to call some data from server based on the date.
constructed code working in PB desktop:
let
Now = DateTime.LocalNow(),
Yesterday = Date.AddDays(Now, -1),
Date = DateTime.ToText(Yesterday, "dd-MM-yyyy hh:mm") ,
Date2 = DateTime.ToText(Now, "dd-MM-yyyy hh:mm"),
Url = "http://Yoursite.com/data/glovadata/search/csv?"&StartTimeLocal=Uri.BuildQueryString(Date)&EndTimeLocal=Uri.BuildQueryString(Date2),
WebContent = Web.Contents(Url),
Kilde = Csv.Document(WebContent,[Delimiter=";", Columns=23, Encoding=1252, QuoteStyle=QuoteStyle.None]),
in
KildeI have constructed the code which works fine in PB desktop, but cannot refresh automatically.
A workaround was introduced by Chris Webb: https://blog.crossjoin.co.uk/2016/08/23/web-contents-m-functions-and-dataset-refresh-errors-in-power-bi/
Using his method, I tried to reconstruct the code I have. However it does not look good as EOF errors and etc is there. Will someone with expertise look at it, I shall thank you in advance.
Let
Now = DateTime.LocalNow(),
Yesterday = Date.AddDays(Now, -1),
Date = DateTime.ToText(Yesterday, "dd-MM-yyyy hh:mm") ,
Date2 = DateTime.ToText(Now, "dd-MM-yyyy hh:mm"),
Terms =
#table({"Dato1","Dato2"},
{{Uri.BuildQueryString(Date),Uri.BuildQueryString(Date2)}}),
Successful = (Dato1 | Dato2) =>
let
Source =
Csv.Document(
Web.Contents(
"http://Yoursite.com/data/glovadata/search/csv?",
[Query=[StartTimeLocal==Dato1]&[EndTimeLocal==Dato2]]
),[Delimiter=";", Columns=23, Encoding=1252, QuoteStyle=QuoteStyle.None]
),
Success = Source[success]
in
Success,
Output = Table.AddColumn(
Terms,
"Search Successful",
each SearchSuccessful([Dato1&Dato2])
)
in
outputthanks
1 Reply
- v-juanli-msftCommunity Support
Hi Anonymous
Do you add web data source under on-premise gateway as this article ?
https://docs.microsoft.com/en-us/power-bi/refresh-scheduled-refresh%C2%A0#gateway-connection
Go to Dataset setting->schedule refresh, Give the credential as used in desktop for the data source.
If you didn't configure the schedule refresh setting for your web source before, please use your own code and try to set the setting as above.
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.