Power Query
published
Search
K
Comment on page

Table.SelectColumns

Table.SelectColumns

Returns a table with only the specified columns.
function (table as table, optional columns as nullable any, optional missingField as nullable any) as table

Description

Returns the table with only the specified columns. missingField: (Optional) What to do if the columnn does not exist. Example: MissingField.UseNull or MissingField.Ignore.

Category

Table.Column operations

Examples

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")
Table.FromRecords({ [Name = "Bob"], [Name = "Jim"] , [Name = "Paul"] , [Name = "Ringo"] })
Only include columns [CustomerID] and [Name].
Table.SelectColumns(Table.FromRecords({[CustomerID=1, Name="Bob", Phone = "123-4567"]}), {"CustomerID", "Name"})
Table.FromRecords({[CustomerID=1, Name="Bob"]})
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.
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)
Table.FromRecords({[CustomerID=1, NewColumn=null]})