Skip to main content

Table.AddColumn

Tiek pievienota kolonna ar norādīto nosaukumu. Vērtība tiek aprēķināta, izmantojot norādīto atlases funkciju un kā ievades datus lietojot katru rindu.

Syntax

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

Remarks

Tabulai table tiek pievienota kolonna ar nosaukumu newColumnName. Kolonnas vērtības tiek aprēķinātas, izmantojot norādīto atlases funkciju columnGenerator un kā ievades datus lietojot katru rindu.

Examples

Example #1

Pievienot skaitļu kolonnu ar nosaukumu "TotalPrice" tabulā, ar katru vērtību kā kolonnu [Price] un [Shipping] summu.

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],
type number
)

Result:

Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100, Shipping = 10, TotalPrice = 110],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5, Shipping = 15, TotalPrice = 20],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25, Shipping = 10, TotalPrice = 35]
})

Category

Table.Transformation