通过变量引用列 [英] Reference a column by a variable
本文介绍了通过变量引用列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在创建另一列时通过变量引用表列,但我无法获得语法:
I want to reference a table column by a variable while creating another column but I can't get the syntax:
t0 = Table.FromRecords({[a = 1, b = 2]}),
c0 = "a", c1 = "b",
t1 = Table.AddColumn(t0, "c", each([c0] + [c1]))
我收到错误未找到记录的字段c0".它将 c0
理解为文字,但我想要 c0
中包含的文本值.怎么做?
I get the error the record's field 'c0' was not found. It is understanding c0
as a literal but I want the text value contained in c0
. How to do it?
我使用这个灵感来自接受的答案:
I used this inspired by the accepted answer:
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
这篇关于通过变量引用列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文