Introduction
In power automate you will often find yourself using logic to determine an output for example if a value is true you want to send an email false you don’t want to send a email.
What is the difference?
Condition
- A Condition is a predefined action that evaluates a specific statement or value to determine if it’s true or false.
- It’s often represented visually in Power Automate as a logic block with two outcomes: “If Yes” or “If No.” You can add actions based on those outcomes.
- Example: “If the variable = TRUE send a Email.”
- Can take longer to run automation
Expression
- An Expression is a more flexible, code-based approach that allows you to write logic using functions and outputs. Expressions use the Power Automate language and allow for complex calculations or evaluations.
- Example:
length(triggerBody()?['fullname']) > 100
checks if users full name length is greater than 100 characters. - Quicker at running within automation
Condition
Conditions are very simple to set up and in most cases require no code, just pure logic.
For this example we are going to look at employee table and do the following based on the outputs from the SharePoint List:
- Work location = “Hybrid” and Has Car = False, Car Needed = TRUE
- Work location = “Hybrid” and Has Car = True, Car Needed = False
- Work location = “Remote” and Has Car = False, Car Needed = False
- Work location = “Remote” and Has Car = true, Car Needed = False
- Work location = “Office” and Has Car = False, Car Needed = True
- Work location = “Office” and Has Car = true, Car Needed = False
Expressions
At first expressions can be a bit more difficult to set up, there is a slight learning curve to understand how expressions work and what logic can be applied.
If we use the same logic as we did for the condition:
- Work location = “Hybrid” and Has Car = False, Car Needed = TRUE
- Work location = “Hybrid” and Has Car = True, Car Needed = False
- Work location = “Remote” and Has Car = False, Car Needed = False
- Work location = “Remote” and Has Car = true, Car Needed = False
- Work location = “Office” and Has Car = False, Car Needed = True
- Work location = “Office” and Has Car = true, Car Needed = False
if(
and(equals(items('For_each')?['WorkLocation/Value'], 'Hybrid'), equals(items('For_each')?['HasCar_x003f_'], false)),
true,
if(
and(equals(items('For_each')?['WorkLocation/Value'], 'Hybrid'), equals(items('For_each')?['HasCar_x003f_'], true)),
false,
if(
and(equals(items('For_each')?['WorkLocation/Value'], 'Remote'), equals(items('For_each')?['HasCar_x003f_'], false)),
false,
if(
and(equals(items('For_each')?['WorkLocation/Value'], 'Remote'), equals(items('For_each')?['HasCar_x003f_'], true)),
false,
if(
and(equals(items('For_each')?['WorkLocation/Value'], 'Office'), equals(items('For_each')?['HasCar_x003f_'], false)),
true,
if(
and(equals(items('For_each')?['WorkLocation/Value'], 'Office'), equals(items('For_each')?['HasCar_x003f_'], true)),
false,
null
)
)
)
)
)
)
As you can see from the screenshot below this has been greatly simplified by using an expression only 1 action is required which is the ‘Update item’ and the expression can go directly in a column level allowing multiple columns to be updated depending on certain logic
Outcome
In the two scenarios above we ran both automations, the first one using the conditions took 7 seconds to run updating 14 records
When we did the test using the expression the flow ran in 4 seconds making it alot quicker to update
Although there doesn’t seem to be a lot of difference between the two times, 3 seconds is a lot of difference per action, your scenario might just be a simple flow but over time as more actions get added and you loop through more records this can gradually slow down your flow and thus taking longer for end users to receive that information, this is especially important when using flows inside Canvas Apps.
Conditions are very useful and come in handy in all sorts of scenarios however to handle more complex logic and multiple updates to certain fields expressions makes it a lot easier. Also when dealing with blank data formulas is easier to handle in most cases