How to use if expression in Power Automate

This is one of easiest and simplest blogs that I am writing but yet quite useful. In this blog I am going to discuss the following topics

  • How to compare using the if expression in Power Automate?
  • How to compare with null using if expression in Power Automate?

Frankly speaking it’s quite easy. But for someone not having prior experience in development and jumping into Power Automate development, it may be bit difficult to understand in the way it works.

Let’s take a simple example here. I have the following flow where I am querying an account record and then depending on the Industry code I will set the variable X.

If expression in Power Automate

I will set the value of X depending on the Industry code. If Industry code is 1, it is Yes else No. But how do we set this expression.

If you are starting with expressions, this is the most obvious expression that will come to your mind.

if(outputs('AccountRecord')?['body/industrycode'] = 1, 'Yes', 'No')

If you try to set the expression then you will get an error. This is because “=” operator is not supported in expressions. For that we need to use the equals function. So the below expression need to be rewritten as.

if(equals(outputs('AccountRecord')?['body/industrycode'], 1), 'Yes', 'No')

How do I then compare != ? Below is the expression to do the same.

if(not(equals(outputs('AccountRecord')?['body/industrycode'], 1)), 'Yes', 'No')

Now probably the most important! How do I compare with null. Because by this time you must have understood that you cannot use the != null

Below is the expression to do the same. Basically we shall be using the empty function.

if(empty(outputs('AccountRecord')?['body/industrycode']), 'Yes', 'No')

Hope this helped!

You may also like the below posts

Debajit Dutta
Business Solutions MVP