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 (trueorfalse).List.AnyTruescans these values and reports whether any of them istrue.
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:
| Student | Score |
|---|---|
| Aanya | 62 |
| Bilal | 58 |
| Carmen | 71 |
| Diego | 49 |
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:
| Customer | Region | Amount |
|---|---|---|
| Acme | North | 120 |
| Globex | South | 640 |
| Initech | East | 95 |
| Umbrella | West | 305 |
| Wayne | North | 80 |
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:
| Customer | Region | Amount |
|---|---|---|
| Acme | North | 120 |
| Globex | South | 640 |
| Umbrella | West | 305 |
| Wayne | North | 80 |
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 notruevalue to find. - It evaluates lazily and short-circuits. The scan stops at the first
trueelement, so later items are never checked. - Pair it with
List.Transformwhen you start from a list of values rather than booleans.List.Transformturns each value intotrue/false, thenList.AnyTruereduces that to a single result. List.AnyTrueis the flexible alternative to chaining theoroperator. Useorfor a fixed handful of conditions, andList.AnyTruewhen 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.Containsis 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.AnyTrueforList.Countover the sameList.Transformoutput.
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: