Table.SelectColumns
Keeps only the columns you name, in the order you name them.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.SelectColumns(table as table, columns as any, optional missingField as nullable number) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to take columns from. |
columns | any | A column name, or a list of names. |
missingField | nullable number optional | What to do when a named column isn't there: MissingField.Error (the default), MissingField.Ignore, or MissingField.UseNull for a column of nulls. |
Returns
table. The named columns, in the list's order, with every row.
Remarks
- The list's order is the new column order: choosing columns can reorder them too.
- This is the step Choose Columns writes in Transform data; a column added to the source later doesn't pass it.
Examples
Two columns, shop first
Table.SelectColumns(#table({"Product", "Price", "Shop"}, {{"Chair", 50, "Oslo"}}), {"Shop", "Product"})
| Shop | Product |
|---|---|
| Oslo | Chair |
A column that may not be there, as nulls
Table.SelectColumns(#table({"Product", "Price"}, {{"Chair", 50}}), {"Product", "Discount"}, MissingField.UseNull)
| Product | Discount |
|---|---|
| Chair | null |
A missing column is an error by default
Table.SelectColumns(#table({"Product", "Price"}, {{"Chair", 50}}), {"Product", "Discount"})
Result: an error.
[Reason = "Expression.Error", Message = "The column 'Discount' of the table wasn't found.", Detail = null]
Related functions
Table.RemoveColumns, Table.ReorderColumns, Table.ColumnNames.