Table.AddColumn
TableAdds a new column with values computed from a function applied to each row.
Syntax
Table.AddColumn(table as table, newColumnName as text, columnGenerator as function, optional columnType as nullable type) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The input table to add a column to. |
newColumnName | text | Yes | The name of the new column. |
columnGenerator | function | Yes | A function evaluated for each row to produce the new column's value. |
columnType | type | No | Optional type annotation for the new column. |
Return Value
table — The 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 | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | Alice | Widget A | Widgets | 25 | 4 | 1/15/2024 | East | 100 |
| 2 | 2 | Bob | Gadget B | Gadgets | 50 | 2 | 1/18/2024 | West | 100 |
| 3 | 3 | Charlie | Widget C | Widgets | 15 | 10 | 2/1/2024 | East | 150 |
| 4 | 4 | Alice | Gadget D | Gadgets | 75 | 1 | 2/10/2024 | North | 75 |
| 5 | 5 | Diana | Widget A | Widgets | 25 | 6 | 3/5/2024 | West | 150 |
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 | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | Alice | Widget A | Widgets | 25 | 4 | 1/15/2024 | East | No |
| 2 | 2 | Bob | Gadget B | Gadgets | 50 | 2 | 1/18/2024 | West | Yes |
| 3 | 3 | Charlie | Widget C | Widgets | 15 | 10 | 2/1/2024 | East | No |
| 4 | 4 | Alice | Gadget D | Gadgets | 75 | 1 | 2/10/2024 | North | Yes |
| 5 | 5 | Diana | Widget A | Widgets | 25 | 6 | 3/5/2024 | West | No |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks