M/PowerBI/PowerQuery中的[column]和Table.Column(Table, "column")有什么区别 [英] What is the difference between [column] and Table.Column(Table, "column") in M/PowerBI/PowerQuery
问题描述
你好!
我对 [column] 和 Table 之间的差异有疑问.Column(Table, "column") 在 M/PowerBI/PowerQuery 中.
I have a problem with a difference between [column] and Table.Column(Table, "column") in M/PowerBI/PowerQuery.
示例表:
'#____列
1_______a
2_______b
3_______c
Example Table:
'#____column
1_______a
2_______b
3_______c
期望的结果:
'#____列
1_______测试
2_______测试
3_______测试
Desired Result:
'#____column
1_______TEST
2_______TEST
3_______TEST
所以,我目前有以下代码:
So, I currently have the following code:
= Table.ReplaceValue(PrevQueryTable, each Table.Column(PrevQueryTable, "column"),
"TEST",
Replacer.ReplaceValue, {"column"})
这不起作用.结果:
'#____列
1_______a
2_______b
3_______c
'#____column
1_______a
2_______b
3_______c
但是:
= Table.ReplaceValue(PrevQueryTable, each [column],
"TEST",
Replacer.ReplaceValue, {"column"})
确实有效.结果:
'#____列
1_______测试
2_______测试
3_______测试
'#____column
1_______TEST
2_______TEST
3_______TEST
为什么?我怎么能做某事.喜欢第一个做工作吗?(目前正在编写一个函数,它将列名用作字符串.)
Why? And how can I make sth. like the first do work? (Currently writing a function which uses this with column names as strings.)
推荐答案
Table.Column
从一个表列中返回一个列表.
Table.Column
returns a list from taking one table column.
[column]
返回该列中的值当前行.
在这种情况下,我发现 Table.TransformColumns
比 Table.ReplaceValue
更灵活.
In this case, I find Table.TransformColumns
more flexible than Table.ReplaceValue
.
如果您使用 GUI 将几列转换为大写,则会生成如下所示的代码:
If you used the GUI to transform several columns to UPPERCASE it would generate code that looks like this:
= Table.TransformColumns(
PrevQueryTable,
{{"Col1", Text.Upper, type text},
{"Col2", Text.Upper, type text},
{"Col3", Text.Upper, type text}})
这可以作为我们如何编写自己的转换的模板.假设我们有一个列名列表ColumnList
(例如来自Table.ColumnNames
).我们可以通过向每个元素添加转换函数来转换该列表,如下所示:
This can serve as a template for how we want to write our own transformation. Suppose we have a list of column names ColumnList
(from Table.ColumnNames
for example). We could transform that list by adding the transformation functions to each element like so:
= Table.TransformColumns(
PrevQueryTable,
List.Transform(
ColumnList,
each {_, each "TEST", type text}
)
)
例如"col1"
被转换成 {"col1", each "TEST", type text}
这篇关于M/PowerBI/PowerQuery中的[column]和Table.Column(Table, "column")有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!