Table.SelectColumns

Table.SelectColumns(table as table, columns as any, optional missingField as any) as table

返回只含有指定 columnstable

  • table: 提供的表。
  • columns: 要从表 table 中返回的列的列表。返回的表中的列以 columns 中列出的顺序排列。
  • missingField: (可选) 如果此列不存在,要执行什么操作。 示例: MissingField.UseNullMissingField.Ignore
示例:

只包含列 [Name]。

使用情况:
Table.SelectColumns(Table.FromRecords({
    [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
    [CustomerID = 2, Name = "Jim", Phone = "987-6543"] ,
    [CustomerID = 3, Name = "Paul", Phone = "543-7890"] ,
    [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
}), "Name")
输出:
Table.FromRecords({
    [Name = "Bob"],
    [Name = "Jim"] ,
    [Name = "Paul"] ,
    [Name = "Ringo"]
})
示例:

只包含列 [CustomerID] 和列 [Name]。

使用情况:

Table.SelectColumns(Table.FromRecords({[CustomerID=1, Name="Bob", Phone = "123-4567"]}), {"CustomerID", "Name"})

输出:

Table.FromRecords({[CustomerID=1, Name="Bob"]})

示例:

如果包含的列没有退出,则默认结果为错误。

使用情况:

Table.SelectColumns(Table.FromRecords({[CustomerID=1, Name="Bob", Phone = "123-4567"]}), "NewColumn")

输出:

[Expression.Error] The field 'NewColumn' of the record wasn't found.

示例:

如果包含的列没有退出,选项 MissingField.UseNull 将创建包含 null 值的列。

使用情况:

Table.SelectColumns(Table.FromRecords({[CustomerID=1, Name = "Bob", Phone = "123-4567" ]}), {"CustomerID", "NewColumn"}, MissingField.UseNull)

输出:

Table.FromRecords({[CustomerID=1, NewColumn=null]})

results matching ""

    No results matching ""