Table.AddColumn

Table

Adds a new column with values computed from a function applied to each row.

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

Syntax

Table.AddColumn(table as table, newColumnName as text, columnGenerator as function, optional columnType as nullable type) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe input table to add a column to.
newColumnNametextYesThe name of the new column.
columnGeneratorfunctionYesA function evaluated for each row to produce the new column's value.
columnTypetypeNoOptional type annotation for the new column.

Return Value

tableThe input table with an additional column whose values are computed by the columnGenerator function.

Remarks

Table.AddColumn creates a new column by evaluating the columnGenerator function for each row. Use each with bracket notation to reference existing columns.

Always specify the optional columnType parameter (the fourth argument). This improves performance by allowing the engine to optimize the query, and makes the step self-documenting by keeping the column name, transformation, and data type together in a single step rather than requiring a separate Table.TransformColumnTypes call afterward.

Examples

Example 1: Add a calculated column

Table.AddColumn(Sales, "TotalPrice", each [UnitPrice] * [Quantity], type number)
Result
OrderID
CustomerName
Product
Category
UnitPrice
Quantity
OrderDate
Region
TotalPrice
11AliceWidget AWidgets2541/15/2024East100
22BobGadget BGadgets5021/18/2024West100
33CharlieWidget CWidgets15102/1/2024East150
44AliceGadget DGadgets7512/10/2024North75
55DianaWidget AWidgets2563/5/2024West150

Example 2: Add a text column

Table.AddColumn(Sales, "IsExpensive", each if [UnitPrice] >= 50 then "Yes" else "No", type text)
Result
OrderID
CustomerName
Product
Category
UnitPrice
Quantity
OrderDate
Region
IsExpensive
11AliceWidget AWidgets2541/15/2024EastNo
22BobGadget BGadgets5021/18/2024WestYes
33CharlieWidget CWidgets15102/1/2024EastNo
44AliceGadget DGadgets7512/10/2024NorthYes
55DianaWidget AWidgets2563/5/2024WestNo

Compatibility

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