Table.SelectColumns is a Power Query M function that returns a table with only the specified columns, in the order listed, with an optional missingField parameter to handle missing columns. The function returns a table with the selected columns.
Compatible with: Power BI ServicePower BI DesktopExcel Microsoft 365
Syntax
Table.SelectColumns(
table as table,
columns as any,
optional missingField as nullable number,
) as table
Argument
Attribute
Description
table
columns
missingField
optional
The MissingField.Type determines the function’s reaction to operations on missing columns. When omitted, it uses MissingField.Error and generates an error for missing columns. Alternatives include MissingField.UseNull, substituting null for missing columns, and MissingField.Ignore, which ignores missing columns.
Description
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 column does not exist. Example: MissingField.UseNull or MissingField.Ignore.
If the included column does not exist, the default result is an error.
// Output: [Expression.Error] The field 'NewColumn' of the record wasn't found.
Table.SelectColumns(
Table.FromRecords( {[CustomerID = 1, Name = "Bob", Phone = "123-4567"]} ),
"NewColumn"
)
If the included column does not exist, option MissingField.UseNull creates a column of null values.