List.PositionOfAny Function in Power Query

The List.PositionOfAny function in Power Query (M language) returns the position of the by default first occurrence of any item from a list of values in a target list. If none are found, it returns -1.

Syntax

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

The function has the following parameters:

Example: Find the index position of any item from the list {"Mango", "Orange"} in the given source list. The input value is case sensitive.

Power Query M

let
    SourceList = {"Apple", "Banana", "Mango", "Orange"},
    ValuesToFind = {"Mango", "Orange"},
    Position = List.PositionOfAny(SourceList, ValuesToFind)
in
    Position  

The output of the above code is 2.

Example: Not Found.

Power Query M

let
    SourceList = {"Apple", "Banana", "Mango", "Orange"},
    ValuesToFind = {"mango", "orange"},
    Position = List.PositionOfAny(SourceList, ValuesToFind)
in
    Position 

The output of the above code is -1, because none of the values are found. By default, it is case-sensitive.

Example: Case-Insensitive Match.

Power Query M

let
    SourceList = {"Apple", "Banana", "Mango", "Orange"},
    ValuesToFind = {"mango", "orange"},
    Position = List.PositionOfAny(SourceList, ValuesToFind, 0, Comparer.OrdinalIgnoreCase)
in
    Position 

The output of the above code is 2.