Table.AddIndexColumn

Syntax

Table.AddIndexColumn(table as table, newColumnName as text, optional initialValue as nullable number, optional increment as nullable number) as table

About

Appends a column named newColumnName to the table with explicit position values. An optional value, initialValue, the initial index value. An optional value, increment, specifies how much to increment each index value.

Example 1

Add an index column named "Index" to the table.

Table.AddIndexColumn(Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"], [CustomerID = 2, Name = "Jim", Phone = "987-6543"], [CustomerID = 3, Name = "Paul", Phone = "543-7890"], [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]}), "Index")
CustomerID Name Phone Index
1 Bob 123-4567 0
2 Jim 987-6543 1
3 Paul 543-7890 2
4 Ringo 232-1550 3

Example 2

Add an index column named "index", starting at value 10 and incrementing by 5, to the table.

Table.AddIndexColumn(Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"], [CustomerID = 2, Name = "Jim", Phone = "987-6543"], [CustomerID = 3, Name = "Paul", Phone = "543-7890"], [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]}), "Index", 10, 5)
CustomerID Name Phone Index
1 Bob 123-4567 10
2 Jim 987-6543 15
3 Paul 543-7890 20
4 Ringo 232-1550 25