Table.SelectColumns

Table

Returns a table with only the specified columns.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

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

Parameters

NameTypeRequiredDescription
tabletableYesThe input table to select columns from.
columnsanyYesA column name or list of column names to keep.
missingFieldnumberNoControls behavior when a specified column does not exist. Use MissingField.Error (default), MissingField.Ignore, or MissingField.UseNull.

Return Value

tableA table containing only the specified columns, in the order listed.

Remarks

Table.SelectColumns returns a table containing only the columns you specify, in the order you list them. This is the complement of Table.RemoveColumns — use Table.SelectColumns when you want to keep a few columns from a wide table, and Table.RemoveColumns when you want to drop a few columns.

The columns appear in the output in the same order you list them, so this function also serves as a way to reorder columns in a single step.

As a best practice, always provide the third argument MissingField.Ignore to silently skip any columns that do not exist. This prevents broken refreshes if an upstream column is renamed or removed from the data source.

Examples

Example 1: Select specific columns

Table.SelectColumns(Sales, {"Product", "UnitPrice", "Quantity"})
Result
Product
UnitPrice
Quantity
1Widget A254
2Gadget B502
3Widget C1510
4Gadget D751
5Widget A256
6Thingamajig E1201
7Gadget B503
8Widget C158

Example 2: Select and reorder columns

Table.SelectColumns(Sales, {"Region", "CustomerName"})
Result
Region
CustomerName
1EastAlice
2WestBob
3EastCharlie
4NorthAlice
5WestDiana
6EastBob
7WestCharlie
8NorthDiana

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks