Table.AddIndexColumn
TableAdds a sequential index column to a 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 tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The input table to add an index column to. |
newColumnName | text | Yes | The name of the new index column. |
initialValue | number | No | The starting value of the index (default is 0). |
increment | number | No | The increment between consecutive index values (default is 1). |
columnType | type | No | Optional type annotation for the index column. |
Return Value
table — The 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 | |
|---|---|---|---|
| 1 | 1 | Alice | Widget A |
| 2 | 2 | Bob | Gadget B |
| 3 | 3 | Charlie | Widget C |
| 4 | 4 | Alice | Gadget D |
| 5 | 5 | Diana | Widget A |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks