Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

Replace multiple conditions with single Power Automate expression

Posted on February 12, 2023February 27, 2023 by Tom

“I feel that I’ve got too many conditions to handle basic stuff, can I somehow reduce/replace them to simplify my Power Automate flow?”


Conditions, one of the key building blocks in Power Automate. A simple decision: if “something” is true, do this, otherwise do that. But often it’s not that simple and if a condition is false it leads to another condition, another true or false. And the more potential options there’re, the more conditions you’ll need.

Is that really necessary? Isn’t there an easier way than a tree of conditions?

Replace the conditions with if(…) expressions

The Power Automate if(…) expression is the equivalent of the ‘Condition’ action. Instead of adding the action and then deciding e.g. on a value for some field, you can use the if(…) expression to get the correct value right away.

The basic if(…) expression was already explained in the date-formatting article and looks as below.

if(<condition>, <ifConditionIsTrue>, <ifConditionIsFalse>)

What you maybe didn’t know is that you combine them inside each other. Evaluate the first condition, and if it’s false try another evaluation.

if(<condition>, 
  <ifConditionIsTrue>, 
  if(<condition2>, 
    <ifCondition2IsTrue>, 
    <ifCondition2IsFalse>)
)

And it can go on an on, as many ifs as you need. But how do you build such expression?

Start from the last ‘Condition’

Let’s take an example, a flow where you translate a number into more generic value. If the number is less than 3 the value is LOW, for 3 or 4 it’s MID, and if it’s 5 or more it’s HIGH. When using the ‘Condition’ actions it’ll look as below.

To turn it into a single expression with if(…) start from the bottom. The last condition evaluates whether the value is less than 5.

if(less(outputs('Compose_-_Value'), 5),<ifTrue>,<ifFalse>)

You can use the trick with the ‘Filter array’ action if you’re not sure how to write such condition.

If it’s true, use the value MID, otherwise use the value HIGH.

if(less(outputs('Compose_-_Value'), 5), 'MID', 'HIGH')

That was the last condition, now let’s go one step higher, to the previous condition. The flow will reach the 2nd condition only if the first condition is false.

if(<condition>, <ifTrue>, if(less(outputs('Compose_-_Value'), 5), 'MID', 'HIGH'))

The first condition should evaluate whether the value is less than 3.

if(less(outputs('Compose_-_Value'), 3), 
  <ifTrue>, 
  if(less(outputs('Compose_-_Value'), 5), 
    'MID', 
    'HIGH'
  )
)

And if it’s true, it should use the value LOW.

if(less(outputs('Compose_-_Value'), 3), 
  'LOW', 
  if(less(outputs('Compose_-_Value'), 5), 
    'MID', 
    'HIGH'
  )
)

Since there’re no other conditions in the flow, that’s it. A single expression that’ll get the value without branching the flow.

Summary

Whenever you start stacking conditions in your Power Automate flow, you should reconsider whether they are needed, or if you can replace them and simplify the flow. Start from the last condition, convert it into if(…) expression, and keep adding the other conditions around it. At the end it can be a single expression that can replace a whole bunch of the ‘Condition’ actions.

It’s another concept complementing the configuration lists that’ll help you build more efficient and easier to manage flows.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes