Excel 在PowerQuery/M中插入具有值列表的新列
如果我有以下来源:Excel 在PowerQuery/M中插入具有值列表的新列,excel,powerbi,powerquery,m,Excel,Powerbi,Powerquery,M,如果我有以下来源: #"My Source" = Table.FromRecords({ [Name="Jared Smith", Age=24], [Name = "Tom Brady", Age=44], [Name="Hello Tom", Age = null], [Name = "asdf", Age = "abc"] }), 如何从值列表中添加新列,例如: Table.AddColumn(#"My Source
#"My Source" = Table.FromRecords({
[Name="Jared Smith", Age=24],
[Name = "Tom Brady", Age=44],
[Name="Hello Tom", Age = null],
[Name = "asdf", Age = "abc"]
}),
如何从值列表中添加新列,例如:
Table.AddColumn(#"My Source", "New Col", {'x', 'y', 'z', null})
现在,我的表将有三列。如何做到这一点?我是PQ初学者,因此可能有更有效的方法,但这里有一种:
- 将索引列添加到每个表中
- 使用索引列作为键合并这两个表
- 删除索引列
还有另一种方法。它开始时与Ron使用的方法类似,通过添加索引,但不使用merge,而是使用索引作为对适当列表项的引用
let
Source1 = Table.FromRecords({
[Name="Jared Smith", Age=24],
[Name = "Tom Brady", Age=44],
[Name="Hello Tom", Age = null],
[Name = "asdf", Age = "abc"]
}),
#"Added Index" = Table.AddIndexColumn(Source1, "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each {"x", "y", "z", null}{[Index]}),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
#"Removed Columns"
@大卫542是的。如果您有大的表,您应该同时尝试Merge方法和您接受的答案中的方法,看看哪个更快。谢谢,Merge应该更快(我猜,不过需要测试才能看到)。这基本上是为了以一种快速的方式简单地添加额外的数据。
let
Source1 = Table.FromRecords({
[Name="Jared Smith", Age=24],
[Name = "Tom Brady", Age=44],
[Name="Hello Tom", Age = null],
[Name = "asdf", Age = "abc"]
}),
#"Added Index" = Table.AddIndexColumn(Source1, "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each {"x", "y", "z", null}{[Index]}),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
#"Removed Columns"