Forum Discussion
Dynamic Date and element in Power BI URL
Hi everyone,
Plz help me on this.
1. I'm trying to format my URL in the way that it takes 2-3 days prior data
I found out that this code (below) will work for today, but how do I change it 2-3 days before in URL itself?
Date = DateTime.ToText((DateTime.LocalNow()), "yyyy-MM-dd"),
e.g. Today is 12 Jun, but the data it will show in URL is the latest data avialable, which would be 9 or 10th Jun.
So basically i need to create in URL date that would pick up the latest avialable data.
2. In URL some elements would change either number/characteristic.
Is it possible to create something similar to Pythong, as:
Mehay ,
Yes, it's like a macro in Excel.
It keeps all the steps and apply them when the refresh happens.
Hi Mehay ,
We get this error if the page load is slower than the Power Query request, to fix it, use this code:
let Source = Web.BrowserContents("https://www.apple.com/covid19/mobility", [WaitFor = [Timeout = #duration(0,0,0,3)]]), Extract = Html.Table( Source, { {"Link", "#download-card > div.download-button-container > a", each [Attributes][href]} }, [RowSelector="#download-card > div.download-button-container"] ){0}[Link], GetData = Csv.Document(Web.Contents(Extract),[Delimiter=",",Encoding=65001, QuoteStyle=QuoteStyle.None]) in GetDataI just added a timer to delay the load of the page in Power Query.
16 Replies
- MehayHelper I
Just for better understnading.
Thats URL I'm trying to deal with, Apple Mobility Trand report:
https://covid19-static.cdn-apple.com/covid19-mobility-data/2009HotfixDev28/v3/en-us/applemobilitytrends-2020-06-09.csv
I highlighted, what changes with every new report published.
So how can I automize it, in order to get latest report to be uploaded into my Power BI?
Thanks in advance.
- camargos88Community Champion
Hi Mehay ,
Create this recursive function and run it with current date:
(dt as date) as table => let Url = Web.Contents( "https://covid19-static.cdn-apple.com/covid19-mobility-data/2009HotfixDev28/v3/en-us/applemobilitytrends-"&Date.ToText(dt, "yyyy-MM-dd")&".csv" ,[ManualStatusHandling={404}] ), Result = if Value.Metadata(Url)[Response.Status] = 404 then @Query1(Date.AddDays(dt, -1)) else Csv.Document(Url,[Delimiter=",",Encoding=65001, QuoteStyle=QuoteStyle.None]) in ResultReplace the Query1 reference with the function name.
- MehayHelper I
Hi camargos88 ,
Indeed Invoked function is a cool one, i do personally like it.
But in this case it won't make it automized the way i would make it in python let's say.
Moreover., whenever you choose new date of daat to be uploaded, it would open as new Invoked Function every time.
And that means I need to apply all my filters again and again, os is there a way so function wont create new one but will replace existing with all its filters?
Sorry, im quite new in Power BI, and therefore, not that familiar with M language too.
Thnaks.