我想在创建另一列时通过变量引用表列,但无法获取语法:

    t0 = Table.FromRecords({[a = 1, b = 2]}),
    c0 = "a", c1 = "b",
    t1 = Table.AddColumn(t0, "c", each([c0] + [c1]))


我收到未找到记录字段'c0'的错误。它正在将c0理解为文字,但我希望c0中包含文本值。怎么做?

编辑

我用这个是受公认的答案启发:

    t0 = Table.FromRecords({[a = 1, b = 2]}),
    c0 = "a", c1 = "b",
    t1 = Table.AddColumn(t0, "c", each(Record.Field(_, c0) + Record.Field(_, c1)))

最佳答案

其他方式:

let
    t0 = Table.FromRecords({[a = 1, b = 2]}),
    f = {"a","b"},
    t1 = Table.AddColumn(t0, "sum", each List.Sum(Record.ToList(Record.SelectFields(_, f))))
in
    t1

09-27 22:46