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
Table.SelectColumns returns the table with only the specified columns. The columns in the returned table are in the order listed in columns. The missingField parameter (optional) specifies the behavior if a column does not exist.
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.