Table.SelectColumns

语法

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

关于

返回仅具有指定的 columnstable

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

示例 1

只包含列 [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"] })

示例 2

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

使用情况

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

输出

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

示例 3

如果包含的列不存在,则默认结果为错误。

使用情况

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

输出

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

示例 4

如果包含的列不存在,选项 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 ""