Table.SelectColumns

Syntax

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

About

Returns the table with only the specified columns.

  • table: The provided table.
  • columns: The list of columns from the table table to return. Columns in the returned table are in the order listed in columns.
  • missingField: (Optional) What to do if the columnn does not exist. Example: MissingField.UseNull or MissingField.Ignore.

Example 1

Only include column [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")
Name
Bob
Jim
Paul
Ringo

Example 2

Only include columns [CustomerID] and [Name].

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

Example 3

If the included column does not exit, the default result is an error.

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

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

Example 4

If the included column does not exit, option MissingField.UseNull creates a column of null values.

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