List.MatchesAny Function (Power Query M)

When you need to check whether at least one item in a list passes a test, List.MatchesAny gives you a quick true or false. You pass it a list and a condition, and it tells you if any item satisfies that condition.

This is handy for filtering rows, validating inputs, or flagging records where a single match is enough to act on.

Syntax of List.MatchesAny Function

List.MatchesAny(list as list, condition as function) as logical

The condition is a predicate function written in each form. List.MatchesAny runs it against every item until one returns true.

  • list (required, list): The list of items you want to test.
  • condition (required, function): A predicate function that takes one item and returns true or false. Write it as an each expression, where _ stands for the current item.

Returns: A logical value (true or false). It is true when at least one item in the list satisfies the condition. An empty list returns false.

In plain terms, it answers the question “does any item here pass this test?”

Example 1: Check if Any Number Is Over a Threshold

Say you have a list of test scores and want to know if anyone scored above 90.

let
Scores = {72,88,64,91,55},
Result = List.MatchesAny(Scores,each _ > 90)
in
Result

Result: true

The predicate each _ > 90 runs against each score. The value 91 clears the threshold, so the result is true. Once one item passes, the rest are not evaluated.

Example 2: Check if Any Item Starts With a Prefix

Now suppose you have a list of region codes and want to know if any of them starts with "EAST".

let
Codes = {"NORTH-01","SOUTH-02","WEST-03"},
Result = List.MatchesAny(Codes,each Text.StartsWith(_,"EAST"))
in
Result

Result: false

The predicate uses Text.StartsWith to test each code. None of the three codes begins with "EAST", so every item fails and the result is false.

Example 3: Check if Any Item Contains Text (Case-Insensitive)

Sometimes you need a match regardless of case. You can pass a comparer inside the predicate, alongside Text.Contains, to handle that.

let
Animals = {"A Brown Fox","A Loyal Dog","A Curious Cat","A Wild Horse"},
Result = List.MatchesAny(Animals,each Text.Contains(_,"cat",Comparer.OrdinalIgnoreCase))
in
Result

Result: true

The predicate calls Text.Contains with Comparer.OrdinalIgnoreCase as the third argument. That makes the search ignore case, so "A Curious Cat" matches the lowercase "cat" and the result is true.

Example 4: Filter Rows Where Any Month Exceeds a Target

You can use List.MatchesAny inside Table.SelectRows to keep rows where any value in a row passes a test. Here you want regions where sales in at least one month went above 5000.

This is the starting table:

RegionJanFebMar
North420051004800
South210019002300
East670072006900
West150018002000

For each row, build a list from the three month columns and keep the row if any month exceeds 5000.

let
Source = Excel.CurrentWorkbook(){[Name="RegionSales"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Jan",Int64.Type},{"Feb",Int64.Type},{"Mar",Int64.Type}}),
Filtered = Table.SelectRows(Typed,each List.MatchesAny({[Jan],[Feb],[Mar]},each _ > 5000))
in
Filtered

Result:

RegionJanFebMar
North420051004800
East670072006900

For each row, {[Jan],[Feb],[Mar]} builds a per-row list of the three values. North keeps because Feb is 5100, and East keeps because all three months top 5000. South and West never cross the target, so they drop out.

Things to keep in mind with List.MatchesAny

  • The second argument is a predicate function, not a value. Write it in each form so _ refers to the current item being tested.
  • To compare against a fixed value, put the comparison inside the predicate, for example each _ > 90 or each Text.StartsWith(_,"EAST").
  • For a case-insensitive text match, pass a comparer such as Comparer.OrdinalIgnoreCase inside the predicate function, as the third argument to Text.Contains or Text.StartsWith.
  • An empty list returns false, since there is no item that can satisfy the condition.
  • List.MatchesAny evaluates the predicate against each item, while List.AnyTrue takes a list of values that are already true or false. To turn raw items into booleans first, run them through List.Transform, then feed that to List.AnyTrue. Use List.MatchesAny when you still need to run a test per item.
  • The function short-circuits. It stops at the first item that returns true and does not check the rest.

Common questions about List.MatchesAny

What is the difference between List.MatchesAny and List.AnyTrue?

List.MatchesAny takes a list and a condition function, then runs that condition against each item. This is close to how List.Contains works, except that one checks for an exact value rather than running a predicate. List.AnyTrue takes a list whose items are already logical values and returns true if any of them is true. Reach for List.MatchesAny when you still need to test each item, and List.AnyTrue when you already have a list of booleans.

What is the difference between List.MatchesAny and List.MatchesAll?

Both take a list and a condition function. List.MatchesAny returns true if at least one item passes the condition. List.MatchesAll is stricter and returns true only when every item passes. So if one match is enough, you want List.MatchesAny. If the whole list has to qualify, switch to List.MatchesAll.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.