Forum Discussion

geemian93's avatar
geemian93
Frequent Visitor
2 years ago
Solved

Creating a Relationship with duplicate values in power Query in Excel

Hello There, I have two tables, 1. Transaction Table and 2. Exchange Rate Table as below. The transaction table records the daily transaction in multiple currecnies while the exchange rate table co...
  • dufoq3's avatar
    2 years ago

    Hi geemian93, with your's sample data it is simple (but you have probably different data)

     

    Result

    let
        TransactionTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJW0lEyNAACI1MQy8jUAEiFBrsoxepEK5miqTEGSRoZICuxRFMC1m+IosTQAFUNRNYYYVMsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateDoc = _t, #"No." = _t, #"AmountTrans." = _t, Currency = _t]),
        ExchRateTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc7BDcAgCAXQXTibCghaBugCTXoy7r9Ga4K94IXLy//83oEyZUYukOB67u/iYYqIMNJEjkisjiUgVxVHicl2LtQdmmPd4D+oRRRdeAYUa2utxSQrORJueufT8QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Daterep." = _t, Currency = _t, #"CurrencyUSD/EUR Rate" = _t]),
        TransactionTableChangedType = Table.TransformColumnTypes(TransactionTable,{{"No.", Int64.Type}, {"AmountTrans.", type number}, {"DateDoc", type date}}, "sk-SK"),
        ExchRateTableChangedType = Table.TransformColumnTypes(ExchRateTable,{{"Daterep.", type date}, {"CurrencyUSD/EUR Rate", type number}}, "en-US"),
        MergedQueries = Table.NestedJoin(TransactionTableChangedType, {"DateDoc"}, ExchRateTableChangedType, {"Daterep."}, "ExchRateTableChangedType", JoinKind.LeftOuter),
        #"Expanded ExchRateTableChangedType" = Table.ExpandTableColumn(MergedQueries, "ExchRateTableChangedType", {"CurrencyUSD/EUR Rate"}, {"CurrencyUSD/EUR Rate"})
    in
        #"Expanded ExchRateTableChangedType"
  • AlienSx's avatar
    2 years ago

    Make sample tables with multi currency transactions and rates together with resulting table. Now it works for single ccy pair. 

    let
        combine = transactions & Table.RenameColumns(rates, {"Daterep.", "Date"}),
        sort = Table.Sort(combine,{{"Date", Order.Ascending}, {"Doc No.", Order.Ascending}}),
        rate_down = Table.FillDown(sort,{"USD/EUR Rate"}),
        filter = Table.SelectRows(rate_down, each ([Currency] = "USD")),
        amount = Table.AddColumn(filter, "EUR Amount", each [#"AmountTrans."] * [#"USD/EUR Rate"])
    in
        amount