OpenBI Docs Buy

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
ParameterTypeDescription
listlistThe list to look in.
valueanyThe value to find.
occurrencenullable number
optional
Occurrence.First (the default), Occurrence.Last, or Occurrence.All for a list of every position.
equationCriteriaany
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

List.Contains, Text.PositionOf, Table.PositionOf.

Last updated · OpenBI Studio 0.3.79