List.Positions
ListReturns a list of zero-based index positions for all elements in the given list.
Syntax
List.Positions(list as list) as listParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list whose positions are to be returned. |
Return Value
list — A list of integers {0, 1, 2, ...} with one entry per element in the source list.
Remarks
List.Positions returns a list of zero-based integer indices, one for each element in the input list. For a list of length N, it returns {0, 1, 2, ..., N-1}. It is equivalent to List.Numbers(0, List.Count(list)).
The primary use case is enabling index-aware iteration: by combining the positions list with the original list using List.Zip, you get {{0, item0}, {1, item1}, ...} pairs that let you know each item's position during a transform. This is the standard M pattern for "transform with index" — something that has no built-in direct syntax.
For an empty list, returns an empty list {}. The result is always consecutive integers starting at 0. If you need indices starting at 1, use List.Transform(List.Positions(list), each _ + 1) or List.Numbers(1, List.Count(list)).
Examples
Example 2: Pair each item with its index using List.Zip
let
Items = {"Alpha", "Beta", "Gamma"},
Indexed = List.Zip({List.Positions(Items), Items})
in
IndexedThe final output — a list of {position, item} pairs for each element in Items.
Result | |
|---|---|
| 1 | {{0, Alpha}, {1, Beta}, {2, Gamma}} |
Example 3: Filter items by even index positions
let
Items = {"A", "B", "C", "D", "E", "F"},
Positions = List.Positions(Items),
EvenIndexItems = List.Transform(
List.Select(Positions, each Number.Mod(_, 2) = 0),
each Items{_}
)
in
EvenIndexItemsThe final output — a list containing only the items at even index positions from the original list.
Result | |
|---|---|
| 1 | {A, C, E} |