Skip to content

Function Friday – Logical Comparisons

Photo by Tima Miroshnichenko from Pexels

Similar to most programming languages, Power Automate contains a number of logical functions for comparing values. These include: and, equals, greater, greaterOrEquals, if, less, lessOrEquals, not, or.

Most of these functions work in the same general manner. The function name is passed two or more parameters. The parameters may be single values or expressions, such as the following:

@equals('There', 'Their')  //returns false
@and(equals('hello', 'goodbye'), equals(1, 2))  //returns false
@less(5, 10)  //returns true

Let’s go through the various functions.

and

The and function checks whether all the expressions passed in are true. Each expression should evaluate as true or false. If they all return true, then the and function returns true. If any of them return false, then the result of the and function is false.

@and(true, true)  //returns true
@and(true, false)  //returns true
@and(true, true, true, false, true)  //returns true

equals

The equals function checks whether the two passed in values are equal to one another. If the values are equal, then it returns true. Otherwise, it returns false. Keep in mind that values that are of different types, but are equivalent will return true. For example, a numeric value of 1 equals a boolean value of true.

@equals(true, 1)  //returns true
@equals('There', 'Their')  //returns false

not

The not function checks to see whether an expression is false. If it’s false, it returns true. Got it?

@not(false)  //returns true
@not(true)  //returns false

or

The or function will return true if any of the passed in expressions return true.

@or(true, false)  //returns true
@or(false, false, false, true, false)  //returns true
@or(false, false, false)  //returns false

greater, greaterOrEquals, less, lessOrEquals

These functions compare values. The first value is compared against the second value.

@greater(100, 50)  //true
@greaterOrEquals(100, 100)  //true
@less('apple', 'pear')  //false

if

The if function is a little different from the other logical comparisons. Other than returning a true or false result, the if function lets you return any value you want if the test expression is true and a different result if the test expression is false.

@if(equals(variableA, variableB), 'potato', 'pizza')
//if variableA == variableB, then 'potato' is returned. Otherwise 'pizza'

Conclusion

For someone with a background in languages where the formats are things like && and || instead of “and” and “or”, it takes a little getting used to. I can’t even count the number of times I’ve written an equals function as “a == b” instead of “equals(a, b)”, but other than that it’s quite straightforward. The logical comparison functions come in extremely handy when you need help control the logic of your flow based on comparing the values you’re working with. So now you know, and knowing is half the battle.

Leave a Reply