Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 38 ยท Approvals and Control Flow

Conditions and Switch: Branching a Flow

Branch a flow with the Condition and Switch actions: basic and advanced mode, AND and OR groups, comparing text safely, empty values, and when Switch beats nested conditions.

A flow that does the same thing for every input is easy to build and rarely useful. Real processes branch: big expenses go to a director, small ones to a manager; urgent tickets page someone, normal ones wait in a queue. Power Automate gives you two branching actions, Condition (two paths) and Switch (many paths from one value).

This lesson shows how to build each, how comparisons really behave (case, empty values, types), and how to keep a flow readable when there are many branches. The runnable examples are labelled stand-ins that evaluate the same kind of logic in JavaScript.

The Condition action

A Condition has two branches: If yes and If no. In the designer you build the test in basic mode with three boxes: a value on the left, an operator (is equal to, is greater than, contains, starts with, is empty and so on) and a value on the right. You can add rows and group them with And or Or, and nest groups.

flowchart TB
    S["Amount"] --> C{"Amount > 500<br/>AND Department is not Finance"}
    C -->|"If yes"| D["Ask the director"]
    C -->|"If no"| M["Ask the manager"]

One Condition, two branches. Either branch may contain any actions, including more conditions.

Every action after the Condition belongs to a branch or comes after both. Actions placed below the Condition (outside the branches) run after whichever branch was taken.

Advanced mode

Switch the Condition to advanced mode (the toggle in the Condition card) to type an expression instead. Both modes build the same thing, but advanced mode lets you use any function:

TEXT
@and(greater(float(triggerBody()?['Amount']), 500), not(equals(triggerBody()?['Department'], 'Finance')))

Use the functions and, or, not, equals, greater, greaterOrEquals, less, lessOrEquals, contains, startsWith, endsWith and empty. Chapter 3 of this course covers expressions in detail.

Comparisons that surprise people

  1. Text comparison is case-sensitive. equals('Approve', 'approve') is false. Normalize both sides with toLower() when the case is not guaranteed.
  2. Numbers that arrive as text compare as text. Values from forms, emails or some connectors are strings. '9' versus '10' as text puts '9' after '10'. Convert with int() or float() first.
  3. Empty and null are different. A missing field yields null; an empty text box yields an empty string. The empty() function returns true for both, which is usually what you want. The safe-navigation operator ?['Field'] returns null instead of failing when a property is missing.
  4. Dates are text too. Compare them after converting with ticks() or formatDateTime(), or use less() on ISO 8601 strings of the same format, which sort correctly as text.

Try these rules in a stand-in that copies the behavior of the comparison functions.

JS Stand-in: comparison pitfalls

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The Switch action

When one value decides among many outcomes, a Switch is flatter than a pile of nested Conditions. You choose the On value (a single expression, such as the ticket priority) and add Case branches, each with an Equals value. A Default branch catches everything else.

flowchart LR
    P["Priority"] --> SW{"Switch"}
    SW -->|"Critical"| A["Page on-call"]
    SW -->|"High"| B["Create urgent task"]
    SW -->|"Normal"| C["Add to queue"]
    SW -->|"Default"| D["Log unknown value"]

Only one case runs. Switch matches one value exactly; it cannot test ranges such as "greater than 500".

Always fill in Default. Without it, an unexpected value (a new priority someone added to the form, a typo) skips the whole Switch silently. Logging the unknown value in Default turns a mystery into a message.

For ranges, use a Condition, or compute a category first with an expression and then switch on it:

TEXT
@if(greater(triggerBody()?['Amount'], 5000), 'large', if(greater(triggerBody()?['Amount'], 500), 'medium', 'small'))
JS Stand-in: range to category, then Switch

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Keeping branching readable

  • Rename every Condition. "Is amount over 500?" is far better than "Condition 3" six months later. Rename actions with a verb phrase.
  • Avoid deep nesting. The designer limits how deeply actions can nest (currently eight levels), and anything beyond three levels is hard to read. Flatten with Switch, early termination (see scope and terminate), or a child flow.
  • Handle both branches. An empty "If no" is fine when nothing should happen, but check that it is a decision, not an oversight.
  • Put shared work after the branches, not copied into each branch.
  • Prefer one test over many. A single and(...) in advanced mode is easier to review than five stacked rows.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which statement about text comparison with equals() is true?

    'Approve' and 'approve' are different text values.
  2. 2. You need different handling for amounts below 100, 100-1000 and above 1000. Which is the best direct fit?

    Switch matches exact values, not ranges, so compute a category first or use Conditions.
  3. 3. Why should a Switch always have a Default branch?

    Default catches new or misspelled values so you can log or handle them.
  4. 4. Which function returns true for both null and an empty string?

    empty() treats null, empty text, empty arrays and empty objects as empty.

Summary

  • Condition gives two branches; build tests in basic mode or type an expression in advanced mode.
  • Text comparisons are case-sensitive, text numbers compare as text, and null differs from an empty string (empty() covers both).
  • Switch picks one of many cases by exact value; always fill in Default.
  • Name branches clearly and avoid deep nesting.

Next: Apply to Each and Loops