List.PositionOfAny
ListReturns the position of the first item in a list that matches any value from a second list.
Syntax
List.PositionOfAny(list as list, values as list, optional occurrence as nullable number, optional equationCriteria as any) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list to search. |
values | list | Yes | The list of values to search for. |
occurrence | nullable number | No | Controls which occurrence to find: Occurrence.First (default), Occurrence.Last, or Occurrence.All. |
equationCriteria | any | No | An optional equation criteria to control how equality is determined. |
Return Value
any — The zero-based index of the first matching item, or -1 if no match is found.
Remarks
List.PositionOfAny searches a list for the first item that matches any value from a second list of targets. It is the multi-target version of List.PositionOf — useful when you need to find where any of several values first appears in a sequence.
Returns -1 if none of the target values are found. The occurrence parameter controls which match to return: Occurrence.First (default) for the earliest match, Occurrence.Last for the latest, and Occurrence.All to return a list of all positions where any target appears. When using Occurrence.All, the return type changes from a number to a list of numbers.
Comparison is case-sensitive for text by default. This function is particularly useful for finding the position of the first delimiter or separator in a list, or for locating the first occurrence of any of a set of sentinel values. For checking presence without needing position, List.ContainsAny is simpler.
Examples
Example 1: Find position of first match from a set of values
List.PositionOfAny({"A", "B", "C", "D", "E"}, {"C", "E"})Result | |
|---|---|
| 1 | 2 |
Example 3: Find all positions of any matching value
List.PositionOfAny({"A", "B", "C", "A", "D", "B"}, {"A", "B"}, Occurrence.All)Result | |
|---|---|
| 1 | {0, 1, 3, 5} |