OpenBI Docs Buy

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
ParameterTypeDescription
tabletableThe table to take columns from.
columnsanyA column name, or a list of names.
missingFieldnullable 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"})
ShopProduct
OsloChair

A column that may not be there, as nulls

Table.SelectColumns(#table({"Product", "Price"}, {{"Chair", 50}}), {"Product", "Discount"}, MissingField.UseNull)
ProductDiscount
Chairnull

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]

Table.RemoveColumns, Table.ReorderColumns, Table.ColumnNames.

Last updated · OpenBI Studio 0.3.79