如何根据公共索引列“国家”组合多个表格以生成货币转换,如下图所示:
当地货币交易 * 汇率 = 货币调整
我不认为(A)和(B)的数学与(C)一致。如果我有 2 英镑,那应该接近 3 美元,而不是 30 美分。
您想要组合两个表之间的行通常称为左连接。您可以单击合并按钮来合并行。您想从 (A) 进行连接并将 (B) 添加到其中。一旦你有了它,你可以使用添加列和乘法来计算货币汇率并应用它。
完成的解决方案类似于最终查询:
section Section1;
shared LocalCurrencyTransactions = let
Source = Csv.Document("Country,LocalCurrencyAmounts
US,1
UK,2.13
JAPAN,328.08
INDIA,66.56
US,2
UK,0.71
JAPAN,109.36
INDIA,133.12"),
#"Promoted Headers" = Table.PromoteHeaders(Source),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Country", type text}, {"LocalCurrencyAmounts", type number}})
in
#"Changed Type";
shared #"FX Rates" = let
Source = Csv.Document("Country,LocalCurrency,USD
US,1,$1.00
UK,0.71,$1.00
JAPAN,109.36,$1.00
INDIA,66.56,$1.00"),
#"Promoted Headers" = Table.PromoteHeaders(Source),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Country", type text}, {"LocalCurrency", type number}, {"USD", Int64.Type}})
in
#"Changed Type";
shared CurrencyAdjustedToUSD = let
Source = LocalCurrencyTransactions,
#"Merged Queries" = Table.NestedJoin(Source,{"Country"},#"FX Rates",{"Country"},"NewColumn",JoinKind.LeftOuter),
#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"LocalCurrency", "USD"}, {"NewColumn.LocalCurrency", "NewColumn.USD"}),
#"Inserted Division" = Table.AddColumn(#"Expanded NewColumn", "NewColumn.ConversionRate", each [NewColumn.USD] / [NewColumn.LocalCurrency], type number),
#"Inserted Multiplication" = Table.AddColumn(#"Inserted Division", "USD", each List.Product({[LocalCurrencyAmounts], [NewColumn.ConversionRate]}), type number),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Multiplication",{"NewColumn.LocalCurrency", "NewColumn.USD", "NewColumn.ConversionRate"})
in
#"Removed Columns";