List.AllTrue is a Power Query M function that checks if all expressions in a list are true. The function returns true if all expressions are true, otherwise false.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
List.AllTrue( list as list ) as logical
Description
The primary role of the List.AllTrue function is to evaluate whether all expressions in a list are true. This function can streamline your logical tests, making your code more concise and readable.
Examples
Let’s delve into some examples to illustrate the power and simplicity of the List.AllTrue function. Suppose you’re writing a conditional statement to verify three conditions. The traditional approach would be to use an if..then..else statement, like so:
if [Column1] > 3 and [Column2] = "Teacher" and [Column3] <> null then true else false
However, you can achieve the same result with less code by employing the List.AllTrue function. Here’s how you can rewrite the above statement using List.AllTrue:
List.AllTrue( { [Column1] > 3, [Column2] = "Teacher", [Column3] <> null } )
The function will return ‘true’ if all conditions are met, and ‘false’ if any one of them is not.
Let’s consider a scenario where one of the expressions in the list is false. In this case, the List.AllTrue function will return ‘false’. For instance:
List.AllTrue( { true, true, 10 > 5 } ) // Output: true
Even though the first two expressions are true, the third one is false, leading to a ‘false’ output. Conversely, if all expressions are true, the function will return ‘true’:
List.AllTrue( { true, true, 10 < 5 } ) // Output: false
In conclusion, the List.AllTrue function is a handy tool for simplifying complex logical tests in Power Query M language.
Related functions
Other functions related to List.AllTrue are:
