List.PositionOfAny

List

Returns the position of the first item in a list that matches any value from a second list.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

List.PositionOfAny(list as list, values as list, optional occurrence as nullable number, optional equationCriteria as any) as any

Parameters

NameTypeRequiredDescription
listlistYesThe list to search.
valueslistYesThe list of values to search for.
occurrencenullable numberNoControls which occurrence to find: Occurrence.First (default), Occurrence.Last, or Occurrence.All.
equationCriteriaanyNoAn optional equation criteria to control how equality is determined.

Return Value

anyThe 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
Result
12

Example 2: No match found

List.PositionOfAny({10, 20, 30}, {99, 100})
Result
Result
1-1

Example 3: Find all positions of any matching value

List.PositionOfAny({"A", "B", "C", "A", "D", "B"}, {"A", "B"}, Occurrence.All)
Result
Result
1{0, 1, 3, 5}

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks