# Power Automate: lessOrEquals function

Comparisons are an essential part of any platform, and Power Automate has excellent functions to help us with that. The lessOrEquals function is incredibly handy and does what it says on the tin. For example, it compares if the first value is lower or equals to the second value.

## Usage

It follows a simple pattern.

1. Integer, Float, or String to compare
2. Integer, Float, or String for the comparison item.

``````lessOrEquals(10,100)

will return

true
``````

It also works with float numbers:

``````lessOrEquals(12.2,12.3)

will return

true
``````

Now let’s look at strings. They are much more complex to compare, and results may be strange in some areas. For example:

``````lessOrEquals('a','b')

returns

true
``````

It makes sense since we know that “a” comes before “b”, but so does:

``````lessOrEquals('.a','b')

returns

true
``````

Depending on how you look at it, it makes sense, or it’s wrong. Another example is with a string that contains a number.

``````lessOrEquals('1','b')

returns

true
``````

Depending on where you look, numbers come before or after when you sort alphabetically, so in this case, you know that numbers are not considered first. We can continue to find examples, but I think this proves my point. You can use it to understand if something is ordered, being a name is “before” another, but be careful and test your Flow. You may get unexpected results.

Let’s look at an array:

``````lessOrEquals(createArray(1,2,3),createArray(4,5))

will return an error:

Unable to process template language expressions in action 'Compose' inputs at line '1' and column '6323': 'The template language function 'lessOrEquals' expects all of its parameters to be either integer or decimal numbers. Found invalid parameter types: 'Array'.'.
``````

No arrays allowed. Finally, let’s try with boolean values:

``````lessOrEquals(true,false)

will return an error

Unable to process template language expressions in action 'Compose_2' inputs at line '1' and column '6323': 'The template language function 'lessOrEquals' expects all of its parameters to be either integer or decimal numbers. Found invalid parameter types: 'Boolean'.'.
``````

The specification is evident here. Boolean values are not comparable, but it’s nice to try.

## Limitations

Like we’ve seen above, arrays, boolean values, and other objects outside strings, integers, and floats are not allowed. I can’t consider this as a limitation since it doesn’t make sense to compare them, but I wanted to stress it here since, in some cases, we can use variables or “Compose” action, for example, so that these values may exist.

## Recommendations:

Here are some things to keep in mind.

### Use “debug” compose actions.

Since the comparison will return true or false, sometimes it’s tricky to understand how the calculation is done, depending on how complex the expression is. So I recommend using Compose actions to have the values that go “in” the function. This way, if the value doesn’t make sense, you can understand, based on the parameters, why it was calculated that way.

### Please don’t use it on strings.

We are comparing if a string is “lower” than the other works, but it’s pretty hard to understand the outcome, as we’ve seen above. So even if the string contains a number, use the int function first and then compare. Otherwise, there’s no real reason to compare strings like this.

If you have a good example, I want to know about it. Would you please email me or interact on Twitter?

### Don’t nest

There’s no real reason to do it. Furthermore, if you try to nest lessOrEquals functions, you’ll receive an error since boolean values are not comparable. So be very careful to avoid breaking Flows.

## Sources:

Microsoft’s lessOrEquals Function Reference

Back to the Power Automate Function Reference.

Photo by Gabriella Clare Marino on Unsplash

#### Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →