OpenBI Docs Buy

Table.AddIndexColumn

Numbers the rows in a new column: from 0 by ones, or from a start and by a step you choose.

Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.

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
ParameterTypeDescription
tabletableThe table to number.
newColumnNametextThe name of the new column.
initialValuenullable number
optional
The first row's number; 0 when left out.
incrementnullable number
optional
What is added from one row to the next; 1 when left out.
columnTypenullable type
optional
The new column's type, such as Int64.Type.

Returns

table. The table with the numbers as its last column.

Remarks

  • The numbers follow the rows' order at this step: sort first when the order matters.

Examples

Line numbers from 1

let
    Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
    Table.AddIndexColumn(Lines, "Line", 1, 1, Int64.Type)
ProductPriceUnitsLine
Chair5041
Desk12012
Lamp3063

From 10, by tens

let
    Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
    Table.AddIndexColumn(Lines, "Position", 10, 10)
ProductPriceUnitsPosition
Chair50410
Desk120120
Lamp30630

Left as it is: from 0

let
    Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
    Table.AddIndexColumn(Lines, "Index")
ProductPriceUnitsIndex
Chair5040
Desk12011
Lamp3062

Table.AddColumn, Table.AddRankColumn, Table.Sort, List.Numbers.

Last updated · OpenBI Studio 0.3.79