Power QueryExercises

Table.AddIndexColumn

Table function · By Tahir Nas · Examples run in our simulator · Published · Updated

Adds a running number to each row.

When to use it

Use it to number rows, for example as a line number, a stable sort key or a way to compare a row with the previous one. Sort first: the index follows the current order.

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

initialValue
Starting value (default 0).

Returns

The table with an index column.

Example

Table.AddIndexColumn(#table({"X"}, {{"a"}, {"b"}}), "Line", 1, 1)

Result

XLine
a1
b2

Example: compare each row with the previous

An index starting at 0 lets you look up the row above with {[Index] - 1}.

let T = Table.AddIndexColumn(#table({"Value"}, {{10}, {13}, {12}}), "i", 0, 1) in Table.AddColumn(T, "Change", each if [i] = 0 then null else [Value] - T{[i] - 1}[Value])

Result

ValueiChange
100null
1313
122-1

Both results are produced by the Power Query Exercises simulator, an independent implementation of a documented subset of M, and checked on every build.

Good to know

Common mistakes

The matching command in Excel

Excel for Windows
Add Column > Index Column
What you see
The default index starts at 0; Custom sets the start and increment.

Paths are for the Power Query editor in Excel for Microsoft 365, checked against Microsoft's documentation on 8 November 2026: Add an index column (Microsoft Learn).

Exercises that use Table.AddIndexColumn

Learn more

Related functions

Official documentation: Table.AddIndexColumn on Microsoft Learn.