Forum Discussion

jannie's avatar
jannie
Frequent Visitor
2 years ago
Solved

Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code

Chris Webb wrote this great blog:   https://blog.crossjoin.co.uk/2021/01/10/handling-multiple-url-query-parameters-with-the-same-name-using-web-contents-in-power-query-power-bi/   I have 3 parame...
  • jpessoa8's avatar
    2 years ago

    Hi jannie ,

     

    Since the ticker is not a parameter in the Yahoo Finance API (like period1, period2 and interval are) you cannot follow the approach of [Query=[...

     

    Instead, you can used directly the RelativePath approach :

     

    let
        Source = Csv.Document(Web.Contents("https://query1.finance.yahoo.com/v7/finance/download/", [RelativePath=prmTicker & "?period1="& prmStartDate & "&period2=" & prmEndDate & "&interval=1d"]),[Delimiter=",", Columns=7, Encoding=65001, QuoteStyle=QuoteStyle.None])
    in
        Source

     

    For documentation, if ticker was a parameter and you wanted to use the [Query=[... approach it will be like this:

     

    let
        Source = Csv.Document(Web.Contents("https://query1.finance.yahoo.com/v7/finance/download/TSLA", [Query=[ticker = prmTicker, period1= prmStartDate, period2= prmEndDate, interval="1d"]]),[Delimiter=",", Columns=7, Encoding=65001, QuoteStyle=QuoteStyle.None])
    in
        Source

     

    Hope this answer solves your problem!
    If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudo 👍
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Jorge Pessoa