Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
praveenjujare
Helper I
Helper I

Yahoo link not working

stockquotes as text)as table =>

 

let

 

EndDate= Number.Round(Duration.TotalSeconds(DateTime.LocalNow()- #datetime(1970,1,1,0,0,0)),0),

 

// Get JSON data from Yahoo Finance API

 

Source = Json.Document(Web.Contents(https://query2.finance.yahoo.com, [RelativePath = "/v8/finance/chart/" & stockquotes & "?period1"=1691314869 & "&period2=" & Text.From(EndDate) & "&interval=1d&events=history&includeAdjustedClose=true"])

 

),

 

// Parse JSON response

 

 

 

JsonResponse = Json.Document(Source),

 

 

 

// Check for errors in the JSON response

 

 

 

Chart = JsonResponse[chart],

 

 

 

Result = Chart[result]{0},

 

 

 

Meta = Result[meta],

 

 

 

Indicators = Result[indicators],

 

 

 

Quote = Indicators[quote]{0},

 

 

 

Timestamps = Result[timestamp],

 

 

 

AdjClose = Indicators[adjclose]{0}[adjclose],

 

 

 

// Convert timestamps (in seconds) to dates

 

 

 

Dates = List.Transform(Timestamps, each DateTime.From(#datetime(1970, 1, 1, 0, 0, 0)) + #duration(0, 0, 0, _)),

 

 

 

// Combine the data into a table

 

 

 

DataTable = Table.FromColumns({

 

 

 

Dates,

 

 

 

Quote[open],

 

 

 

Quote[high],

 

 

 

Quote[low],

 

 

 

Quote[close],

 

 

 

AdjClose,

 

 

 

Quote[volume]

 

 

 

}, type table [Date=datetime, Open=number, High=number, Low=number, Close=number, #"Adj Close"=number, Volume=Int64.Type]),

 

 

 

// Change data types (if necessary, although columns should already be typed correctly)

 

 

 

#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),

 

 

 

    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"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"

 

 

 

 

Expression.Error: We cannot apply operator & to types Number and Text.

Details:

 

 

 

    Operator=&

 

 

 

    Left=1691314869

 

 

 

    Right=&period2=

 

 

 

before it was working

(stockquotes as text)as table =>

 

 

 

 

let

 

 

 

    EndDate= Number.Round(Duration.TotalSeconds(DateTime.LocalNow()- #datetime(1970,1,1,0,0,0)),0),

 

 

 

    Source = Csv.Document(Web.Contents(https://query1.finance.yahoo.com/,[RelativePath= "v7/finance/download/"&stockquotes&"?period1=1691314869&period2=" & Text.From(EndDate) & "&interval=1d&events=history&includeAdjustedClose=true"]),[Delimiter=",", Columns=7, Encoding=65001, QuoteStyle=QuoteStyle.None]),

 

 

 

    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),

 

 

 

    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"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"

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

@praveenjujare 

 

Both of those queries are missing double quotes around the URL.  It should be

 

"https://query2.finance.yahoo.com"

 

 

 

But the error you posted about is caused because you have a double quote in the wrong place, it should be

 

"?period1=1691314869" & "&period2="

 

 

Here's the full query

(stockquotes as text)as table =>

let

EndDate= Number.Round(Duration.TotalSeconds(DateTime.LocalNow()- #datetime(1970,1,1,0,0,0)),0),

// Get JSON data from Yahoo Finance API
Source = Json.Document(Web.Contents("https://query2.finance.yahoo.com", [RelativePath = "/v8/finance/chart/" & stockquotes & "?period1=1691314869" & "&period2=" & Text.From(EndDate) & "&interval=1d&events=history&includeAdjustedClose=true"])
),

// Parse JSON response
JsonResponse = Json.Document(Source),

// Check for errors in the JSON response
Chart = JsonResponse[chart],

Result = Chart[result]{0},

Meta = Result[meta],

Indicators = Result[indicators],

Quote = Indicators[quote]{0},

Timestamps = Result[timestamp],

AdjClose = Indicators[adjclose]{0}[adjclose],

// Convert timestamps (in seconds) to dates
Dates = List.Transform(Timestamps, each DateTime.From(#datetime(1970, 1, 1, 0, 0, 0)) + #duration(0, 0, 0, _)),

// Combine the data into a table
DataTable = Table.FromColumns({
Dates,
Quote[open],
Quote[high],
Quote[low],
Quote[close],
AdjClose,
Quote[volume]
}, type table [Date=datetime, Open=number, High=number, Low=number, Close=number, #"Adj Close"=number, Volume=Int64.Type]),

// Change data types (if necessary, although columns should already be typed correctly)
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),

#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"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"

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

1 REPLY 1
PhilipTreacy
Super User
Super User

@praveenjujare 

 

Both of those queries are missing double quotes around the URL.  It should be

 

"https://query2.finance.yahoo.com"

 

 

 

But the error you posted about is caused because you have a double quote in the wrong place, it should be

 

"?period1=1691314869" & "&period2="

 

 

Here's the full query

(stockquotes as text)as table =>

let

EndDate= Number.Round(Duration.TotalSeconds(DateTime.LocalNow()- #datetime(1970,1,1,0,0,0)),0),

// Get JSON data from Yahoo Finance API
Source = Json.Document(Web.Contents("https://query2.finance.yahoo.com", [RelativePath = "/v8/finance/chart/" & stockquotes & "?period1=1691314869" & "&period2=" & Text.From(EndDate) & "&interval=1d&events=history&includeAdjustedClose=true"])
),

// Parse JSON response
JsonResponse = Json.Document(Source),

// Check for errors in the JSON response
Chart = JsonResponse[chart],

Result = Chart[result]{0},

Meta = Result[meta],

Indicators = Result[indicators],

Quote = Indicators[quote]{0},

Timestamps = Result[timestamp],

AdjClose = Indicators[adjclose]{0}[adjclose],

// Convert timestamps (in seconds) to dates
Dates = List.Transform(Timestamps, each DateTime.From(#datetime(1970, 1, 1, 0, 0, 0)) + #duration(0, 0, 0, _)),

// Combine the data into a table
DataTable = Table.FromColumns({
Dates,
Quote[open],
Quote[high],
Quote[low],
Quote[close],
AdjClose,
Quote[volume]
}, type table [Date=datetime, Open=number, High=number, Low=number, Close=number, #"Adj Close"=number, Volume=Int64.Type]),

// Change data types (if necessary, although columns should already be typed correctly)
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),

#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"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"

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.