List.PositionOf
Where a value sits in a list: its position counted from 0, or every position it has.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.PositionOf(list as list, value as any, optional occurrence as nullable number, optional equationCriteria as any) as any
| Parameter | Type | Description |
|---|---|---|
list | list | The list to look in. |
value | any | The value to find. |
occurrence | nullable number optional | Occurrence.First (the default), Occurrence.Last, or Occurrence.All for a list of every position. |
equationCriteria | any optional | How two values count as equal: a comparer or a key function. |
Returns
any. A number, -1 when the value is not there; with Occurrence.All a list of numbers, empty when it is not there.
Remarks
- Positions start at 0: the first item is position 0.
Examples
The first Tea
List.PositionOf({"Coffee", "Tea", "Milk", "Tea"}, "Tea")
1
Every Tea
List.PositionOf({"Coffee", "Tea", "Milk", "Tea"}, "Tea", Occurrence.All)
{1, 3}
Not on the list
List.PositionOf({"Coffee", "Tea", "Milk"}, "Juice")
-1