Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Using Power Query to pull exchanges rates of different dates

Hi everyone,   I have been looking for the solution in previous threads, but could not find one. I will try to explain the issues I am having and the solution I seek.   We have a dataset that con...
  • v-lid-msft's avatar
    6 years ago

    Hi Anonymous ,

     

    We can add a custom column using following formula and expand it to meet your requirement:

     

     

    let
        url="https://www.xe.com/currencytables/?from="&[Currency]&"&date="&Date.ToText([Date],"YYYY-MM-DD"),
        CurrencyTable = Web.Page(Web.Contents(url)){0}[Data],
        SelectTable = Table.SelectColumns(CurrencyTable,{"Currency code ▲▼","Units per "&[Currency]}),
        Ta = Table.RenameColumns(SelectTable,{{"Currency code ▲▼","To Currency Code"},{"Units per "&[Currency],"Currency Number"}})
    in  
        Ta

     

     

    All the Query is here:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc0xCsAgDAXQu2QWYjQWHdtaXEvFSbz/NRrTFgrhD//xSe9AYICslWw1SzpLCYmQAgzTwWk1eV9fjpjQWVUvDauW7fzGjP5RliaqHu36tuTklMP8vKjXkv/OMMYN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Counter = _t, Amount = _t, Currency = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Counter", Int64.Type}, {"Amount", Int64.Type}, {"Currency", type text}, {"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "CurrencyHistory", each let  
                                                    url="https://www.xe.com/currencytables/?from=" & [Currency]&"&date="&Date.ToText([Date],"YYYY-MM-DD"),
                                                    CurrencyTable = Web.Page(Web.Contents(url)){0}[Data],
                                                    SelectTable = Table.SelectColumns(CurrencyTable,{"Currency code ▲▼","Units per "&[Currency]}),
                                                    Ta = Table.RenameColumns(SelectTable,{{"Currency code ▲▼","To Currency Code"},{"Units per "&[Currency],"Currency Number"}})
                                                 in  
                                                    Ta),
        #"Expanded CurrencyHistory" = Table.ExpandTableColumn(#"Added Custom", "CurrencyHistory", {"To Currency Code", "Currency Number"}, {"CurrencyHistory.To Currency Code", "CurrencyHistory.Currency Number"})
    in
        #"Expanded CurrencyHistory"


    If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.


    Best regards,