List.AnyTrue Function (Power Query M)

When you have a list of true/false values and you want to know if at least one of them is true, List.AnyTrue gives you the answer in one step. It returns true the moment it finds a single true, which makes it a clean fit for OR-style checks.

Syntax of List.AnyTrue Function

List.AnyTrue(list as list) as logical

where:

  • list (required, list): A list whose elements are all logical values (true or false). List.AnyTrue scans these values and reports whether any of them is true.

Returns: a logical true if at least one element in the list is true, and false if every element is false. An empty list returns false.

In plain terms, it answers the question “is anything in this list true?”.

Example 1: Check a Mixed List of Conditions

Here you have a list that holds a few logical values, including the comparison 3>1, which evaluates to true. You want to confirm whether any single value in the list is true.

let
Source = List.AnyTrue({false,false,3>1,false})
in
Source

Result: true

The list has three false values and one expression 3>1 that resolves to true. Because at least one element is true, List.AnyTrue returns true. It stops as soon as it hits that true value.

Example 2: Confirm a List With No True Values

This time every comparison in the list is false. You want to see what List.AnyTrue returns when nothing satisfies the check.

let
Source = List.AnyTrue({1>5,2=7,10<0})
in
Source

Result: false

Each comparison fails. 1>5 is false, 2=7 is false, and 10<0 is false. With no true element anywhere in the list, List.AnyTrue returns false.

Example 3: Test Whether Any Value Meets a Condition

A common job is checking a column of numbers to see if any value passes a threshold. Here you have a Scores table, and you want to know if any student scored above 70.

The starting data looks like this:

StudentScore
Aanya62
Bilal58
Carmen71
Diego49

You pull the Score column into a list, turn each score into a true/false value with List.Transform, then pass that to List.AnyTrue.

let
Source = Excel.CurrentWorkbook(){[Name="Scores"]}[Content],
ScoreList = Source[Score],
AnyAbove70 = List.AnyTrue(List.Transform(ScoreList,each _>70))
in
AnyAbove70

Result: true

List.Transform converts the score list into {false,false,true,false}, since only Carmen’s 71 clears the 70 mark. List.AnyTrue sees that true and returns true. This pairing is the standard way to ask “does any item satisfy X?”.

Example 4: Keep Rows That Match Any of Several Conditions

You can drop List.AnyTrue inside Table.SelectRows to keep rows that match at least one condition. Here you have an Orders table, and you want every order where the Amount is above 300 OR the Region is "North".

The starting data looks like this:

CustomerRegionAmount
AcmeNorth120
GlobexSouth640
InitechEast95
UmbrellaWest305
WayneNorth80

You build a small list of conditions for each row and pass it to List.AnyTrue, so a row survives if any condition is true.

let
Source = Excel.CurrentWorkbook(){[Name="Orders"]}[Content],
Filtered = Table.SelectRows(Source,each List.AnyTrue({[Amount]>300,[Region]="North"}))
in
Filtered

The result is:

CustomerRegionAmount
AcmeNorth120
GlobexSouth640
UmbrellaWest305
WayneNorth80

Acme and Wayne stay because their Region is "North", even though their Amount is low. Globex and Umbrella stay because their Amount is above 300. Initech is the only row dropped, since it fails both conditions. This is how you build OR logic across columns when filtering.

Things to keep in mind with List.AnyTrue

  • Every element in the list must be a logical value. If any element is a different type, the function errors with Expression.Error: We cannot convert a value to type Logical..
  • An empty list returns false, since there is no true value to find.
  • It evaluates lazily and short-circuits. The scan stops at the first true element, so later items are never checked.
  • Pair it with List.Transform when you start from a list of values rather than booleans. List.Transform turns each value into true/false, then List.AnyTrue reduces that to a single result.
  • List.AnyTrue is the flexible alternative to chaining the or operator. Use or for a fixed handful of conditions, and List.AnyTrue when the conditions live in a list or are generated on the fly.
  • If you only need to know whether a single value sits inside a list, List.Contains is a more direct choice than transforming the list into booleans first.
  • To count how many items pass a test rather than just confirm one does, swap List.AnyTrue for List.Count over the same List.Transform output.

Common questions about List.AnyTrue

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

List.AnyTrue takes a list of values that are already true or false and reports whether any of them is true. List.MatchesAny takes a list of values plus one or more condition functions, and tests whether any item satisfies those conditions. So List.AnyTrue works on evaluated booleans, while List.MatchesAny does the testing for you.

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

They are opposites. List.AnyTrue returns true if at least one element is true, which is OR logic. List.AllTrue returns true only when every element is true, which is AND logic.

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.