Table.AddIndexColumn Function in Power Query

The Table.AddIndexColumn function returns a table with a new column with a specific name that, for each row, contains an index of the row in the table.

Syntax

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

Example: Add an index column to the table.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], 
      [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], 
      [CustomerID = 3, Name = "Alia", Phone = "543-7890"], 
      [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], 
      [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], 
      [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], 
      [CustomerID = 7, Name = "Esha", Phone = "574-8864"], 
      [CustomerID = 8, Name = "Anjali", Phone = "574-8864"]
    }
  ), 
  Return = Table.AddIndexColumn(MyTable, "MyIndexColumn")
in
  Return 

The output of the above code is shown below:

Table.AddIndexColumn in Power Query

Example: AAdd an index column to the table, with initial value 3 and its increment to 2 for further values.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], 
      [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], 
      [CustomerID = 3, Name = "Alia", Phone = "543-7890"], 
      [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], 
      [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], 
      [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], 
      [CustomerID = 7, Name = "Esha", Phone = "574-8864"], 
      [CustomerID = 8, Name = "Anjali", Phone = "574-8864"]
    }
  ), 
  Return = Table.AddIndexColumn(MyTable, "MyIndexColumn", 3, 2)
in
  Return  

The output of the above code is shown below:

Table.AddIndexColumn in Power Query