Downloads
Power Query MList: pick and buildBeginner

List.Positions

Returns the position number of every item in a list, starting from zero.

Syntax
List.Positions(list)

Returns: A list of whole numbers from 0 up to one less than the count.

What it does

List.Positions gives you the index of each item: 0 for the first, 1 for the second, and so on. Use it to number rows, to pair an item with its position, or to build a loop over a list where the position matters. It is the list version of an index column.

Syntax and arguments

Example

A check register is a list of cleared amounts. The auditor wants each line numbered so that a question can refer to line 5 rather than to an amount.

let
    Cleared = {250, 1800, 75, 920},
    Positions = List.Positions(Cleared),
    Numbered = List.Transform(Positions, each "Line " & Text.From(_ + 1) & ": " & Text.From(Cleared{_}))
in
    Numbered

Positions is {0, 1, 2, 3}. The label adds 1 so that the first line reads "Line 1", and it uses Cleared{_} to fetch the amount at that position. The result reads "Line 1: 250" and so on.

Example: a second, different use

Adding a row number to a table: Table.AddIndexColumn does this for tables, and List.Positions is the list form.

Things to watch

In business terms

Line numbers on exception reports, sequence checks on invoice or check runs and references in an audit trail all need a stable position. Numbering after the final sort keeps the reference the same as the report the reader sees.

Related functions

All Power Query M functions · View as Markdown · M basics