OpenBI Docs Buy

Table.AddColumn

Adds a column whose value a function works out from each row.

Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Table.AddColumn(table as table, newColumnName as text, columnGenerator as function, optional columnType as nullable type) as table
ParameterTypeDescription
tabletableThe table to add the column to.
newColumnNametextThe new column's name; no column of the table may have it already.
columnGeneratorfunctionA function of one row, often written with each, that gives the row's value for the new column.
columnTypenullable type
optional
The new column's type, such as type number or Int64.Type; any when left out.

Returns

table. The table with the new column as its last one.

Remarks

  • Inside each, [Price] is the row's Price and _ is the whole row as a record.
  • Give a type when the column goes into the model, so that it loads as a number, a date or a text rather than as any.
  • This is the step a custom column writes in Transform data.

Examples

Revenue on each line

let
    Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
    Table.AddColumn(Lines, "Revenue", each [Price] * [Units])
ProductPriceUnitsRevenue
Chair504200
Desk1201120
Lamp306180

With a type

The schema shows the new column's kind.

let
    Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}}),
    Added = Table.AddColumn(Lines, "Revenue", each [Price] * [Units], type number)
in
    Table.Schema(Added)[[Name], [Kind]]
NameKind
Productany
Priceany
Unitsany
Revenuenumber

A label made of two columns

let
    Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
    Table.AddColumn(Lines, "Label", each [Product] & " x" & Text.From([Units]), type text)
ProductPriceUnitsLabel
Chair504Chair x4
Desk1201Desk x1
Lamp306Lamp x6

Table.AddIndexColumn, Table.DuplicateColumn, Table.TransformColumns, Table.SelectRows.

Last updated · OpenBI Studio 0.3.79