Table.AddIndexColumn

Table

Adds a sequential index column to a table.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

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

Parameters

NameTypeRequiredDescription
tabletableYesThe input table to add an index column to.
newColumnNametextYesThe name of the new index column.
initialValuenumberNoThe starting value of the index (default is 0).
incrementnumberNoThe increment between consecutive index values (default is 1).
columnTypetypeNoOptional type annotation for the index column.

Return Value

tableThe input table with an additional column containing sequential index values.

Remarks

Table.AddIndexColumn appends a new column with sequential numeric values. By default, the index starts at 0 and increments by 1. Use the optional parameters to start at a different value or use a custom increment.

Index columns are useful for creating a unique row identifier, enabling row-number-based joins, or preserving original row order before operations that may reorder the data.

Examples

Example 1: Add a 1-based index

Table.SelectColumns(
    Table.AddIndexColumn(Table.FirstN(Sales, 5), "RowNum", 1, 1, Int64.Type),
    {"RowNum", "CustomerName", "Product"}
)
Result
RowNum
CustomerName
Product
11AliceWidget A
22BobGadget B
33CharlieWidget C
44AliceGadget D
55DianaWidget A

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks