货币 ( SCD table ) 和请求 table

Currency ( SCD table ) and Request table

我有两张表,我需要在最需要的时候把当地货币换成美元值。

Table 1 
Product request  / Request Date / Local Currency 
1                   01/01/2022    GBP

Table 2
Currency source / Currency Target / Effective From / Effective To / Rate 
GBP                  USD             01/12/2021       31/12/2021    1.1
GBP                  USD             01/01/2022       31/12/3039    2.2

Table 1 所需的列是美元转换,值为 2.2。

那么在 Power Query 中有没有办法查找此列并为 SCD 货币生成此列 Table?

在 Power Query 中,您可以

  • 读入您的 Table 2 并对其进行缓冲(因此不必为 table 1
  • 中的每一行读取
  • 使用Table.SelectRows方法return得到想要的输出
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

    Source2 = Table.Buffer(Excel.CurrentWorkbook(){[Name="Table2"]}[Content]),
    currencyTable = Table.TransformColumnTypes(Source2,{
        {"Currency source", type text},{"Currency Target", type text},
        {"Effective From", type date},{"Effective To", type date},
        {"Rate", type number}
    }),

    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"Product request", Int64.Type}, {"Request Date", type date}, {"Local Currency", type text}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "USD Rate", each 
        Table.SelectRows(currencyTable, 
            (t)=>t[Currency source] = [Local Currency] and 
                 t[Effective From] <=[Request Date] and 
                 t[Effective To] >= [Request Date])[Rate]{0})
in
    #"Added Custom"