Table.AddColumn

About

Adds a column named newColumnName to a table.

Syntax

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

Arguments

Argument Description
table The Table to modify.
newColumnName The name of the new column to add.
columnGenerator New column generator function.
optional columnType Optional column type for new column

Remarks

The values for the column are computed using the specified function from each row.

Example

Table.AddColumn(Table.FromRecords(  

{  

      [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0, Shipping = 10.00],  

      [OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0, Shipping = 15.00],  

      [OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0, Shipping = 10.00]  

}  

), "TotalPrice", each [Price] + [Shipping])  

Table.AddColumn(Table.FromRecords(  

{  

      [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0, Shipping = 10.00],  

      [OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0, Shipping = 15.00],  

      [OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0, Shipping = 10.00]  

}  

), "TotalPrice", each [Price] + [Shipping])  
OrderID CustomerID Item Price Shipping TotalPrice
1 1 Fishing rod 100 10 110
2 1 1 lb. worms 5 15 20
3 2 Fishing net 25 10 35