Forum Discussion
Yahoo Finance Power Query Link Not Working
Hi,
Just to be clear I have a FREE Yahoo Finance account and have 2x queries in a Power BI report to scrape Web data.
Seems the endpoint has changed plus it now returns JSON as I think someone else has stated.
So changes to one of my original queries:
- Updated the URL to use the v8/finance/chart endpoint; I can confirm the new endpoint doesn't require authentication for basic historical data requests hence works with a free Yahoo Finance account
- Changed from Csv.Document to Json.Document as the new endpoint returns JSON
- Added steps to parse the JSON response and reconstruct the table
Obviously different members with differing scenarios but hopefully this will help members.
(StickerSymbol as text) as table => let EpochReferenceDate = #datetime(1970,1,1,0,0,0), DefaultStartDate = DateTime.From(Date.AddYears(Date.From(DateTime.LocalNow()),-5)), DefaultEndDate = DateTime.From(Date.From(DateTime.LocalNow())), StartDate = if Date.DayOfWeek(DefaultStartDate, Day.Monday) = 5 then Date.AddDays(DefaultStartDate,-1) else /* Saturday */ if Date.DayOfWeek(DefaultStartDate, Day.Monday) = 6 then Date.AddDays(DefaultStartDate,-2) else /* Sunday */ if Date.DayOfWeek(DefaultStartDate, Day.Monday) = 0 then Date.AddDays(DefaultStartDate,-3) else DefaultStartDate, /* Monday */ EndDate = if Date.DayOfWeek(DefaultEndDate, Day.Monday) = 5 then Date.AddDays(DefaultEndDate,-1) else /* Saturday */ if Date.DayOfWeek(DefaultEndDate, Day.Monday) = 6 then Date.AddDays(DefaultEndDate,-2) else /* Sunday */ if Date.DayOfWeek(DefaultEndDate, Day.Monday) = 0 then Date.AddDays(DefaultEndDate,-3) else DefaultEndDate, /* Monday*/ StartOfPeriod = Text.Start(Number.ToText(Duration.TotalSeconds(StartDate - EpochReferenceDate)),10), EndOfPeriod = Text.Start(Number.ToText(Duration.TotalSeconds(EndDate - EpochReferenceDate)),10), Source = Json.Document(Web.Contents("https://query1.finance.yahoo.com/v8/finance/chart/" & StickerSymbol & "?period1=" & StartOfPeriod & "&period2=" & EndOfPeriod & "&interval=1d&events=history&includeAdjustedClose=true")), Result = Source[chart][result]{0}, Timestamps = Result[timestamp], QuoteData = Result[indicators][quote]{0}, AdjCloseData = Result[indicators][adjclose]{0}, CombinedData = Table.FromColumns({ List.Transform(Timestamps, each Date.From(DateTimeZone.FromSecondsSinceEpoch(_))), QuoteData[open], QuoteData[high], QuoteData[low], QuoteData[close], AdjCloseData[adjclose], QuoteData[volume] }, {"Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"}), #"Changed Type" = Table.TransformColumnTypes(CombinedData,{ {"Date", type date}, {"Open", type number}, {"High", type number}, {"Low", type number}, {"Close", type number}, {"Adj Close", type number}, {"Volume", Int64.Type} }) in #"Changed Type"
Hi G05DVD ,
May I ask for your help?
I tried to follow your way of doing that, but unfortunatelly not fully successful.
When I run it for any sticker, in this example ISAC.L there is following result
when checking the error:
How can I deal with that?
- Tomek19821 year agoHelper I
I found the problem. For me it was necessary to replace function:
Date.From(DateTimeZone.FromSecondsSinceEpoch([_]))
with
#datetime(1970, 1, 1, 0, 0, 0) + #duration(0,0,0,_)