December 26, 2024

Comparisons as extremely useful in any programming language or platform, and Power Automate is not the exception. For example, the “greater” function helps us to have two values and compare them.

So let’s check it in more detail.

Usage

It follows a simple pattern.

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

Let’s start with a simple example:

greater(100,10)

will return 

true

It also works with float numbers:

greater(12.3,12.2)

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:

greater('b','a')

returns 

true

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

greater('b','.a')

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.

greater('b','1')

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 “after” another, but be careful and test your Flow. You may get unexpected results.

Let’s look at an array:

greater(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 'greater' 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:

greater(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 'greater' expects all of its parameters to be either integer or decimal numbers. Found invalid parameter types: 'Boolean'.'.

The specification is apparent here. Boolean values are not comparable, but it’s nice to try and be sure.

Limitations

Depending on the size of your string, your expression may return an error, even if it’s correct. Please note that the expressions have a max size of 8,192 characters. If you have an expression that is even bigger than 1000, I would strongly advise breaking it into smaller, manageable formulas.

Finally, as 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 “greater” 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 mind emailing me or interacting on Twitter?

Don’t nest

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

Sources:

Microsoft’s greater Function Reference

Back to the Power Automate Function Reference.

Photo by Randy Tarampi 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 →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon