Table.SelectColumns
TableReturns a table with only the specified columns.
Syntax
Table.SelectColumns(table as table, columns as any, optional missingField as nullable number) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The input table to select columns from. |
columns | any | Yes | A column name or list of column names to keep. |
missingField | number | No | Controls behavior when a specified column does not exist. Use MissingField.Error (default), MissingField.Ignore, or MissingField.UseNull. |
Return Value
table — A 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"})Product | UnitPrice | Quantity | |
|---|---|---|---|
| 1 | Widget A | 25 | 4 |
| 2 | Gadget B | 50 | 2 |
| 3 | Widget C | 15 | 10 |
| 4 | Gadget D | 75 | 1 |
| 5 | Widget A | 25 | 6 |
| 6 | Thingamajig E | 120 | 1 |
| 7 | Gadget B | 50 | 3 |
| 8 | Widget C | 15 | 8 |
Example 2: Select and reorder columns
Table.SelectColumns(Sales, {"Region", "CustomerName"})Region | CustomerName | |
|---|---|---|
| 1 | East | Alice |
| 2 | West | Bob |
| 3 | East | Charlie |
| 4 | North | Alice |
| 5 | West | Diana |
| 6 | East | Bob |
| 7 | West | Charlie |
| 8 | North | Diana |