M/PowerBI/PowerQuery中[column]和Table.Column(Table,“column")有什么区别 [英] What is the difference between [column] and Table.Column(Table, "column") in M/PowerBI/PowerQuery

查看:282
本文介绍了M/PowerBI/PowerQuery中[column]和Table.Column(Table,“column")有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ciao 在那里!

我有 [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.TransformColumnsTable.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", 每个 "TEST", type text}

这篇关于M/PowerBI/PowerQuery中[column]和Table.Column(Table,“column")有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆