Power Apps  

Power Apps - If(), Switch() & Match()

Conditional logic is at the heart of every Power Apps solution.
Whether you are controlling UI behavior, validating data, or routing business logic, choosing the right conditional function matters for readability, performance, and scalability.

This article goes beyond syntax and explains how these functions work internally, when to use each, and how to avoid common anti-patterns.

1. How Conditional Logic Really Works in Power Apps

Power Apps uses a functional, declarative execution model:

  • Formulas do not run once

  • They are recalculated whenever dependencies change

  • There is no guaranteed execution order

This means:

If(varA = 1, Expr1, Expr2)

2. If() — Expression-Based Branching

Choose between expressions, not actions.

If(
    Condition1, Result1,
    Condition2, Result2,
    ...
    DefaultResult
)
  • Conditions evaluated top-down

  • Stops at first true condition

  • Remaining conditions are not evaluated

Example

  • Enable Save only when mandatory fields are filled

  • Disable in View mode

DisplayMode =
If(
    Form1.Mode = FormMode.View,
    DisplayMode.View,
    IsBlank(txtTitle.Text) || IsBlank(ddCategory.Selected),
    DisplayMode.Disabled,
    DisplayMode.Edit
)

3. Nested If()

Nested If() statements:

If(
    A,
    If(
        B,
        If(
            C,
            X,
            Y
        ),
        Z
    ),
    W
)

Note

  • Cognitive overload

  • Hard to debug

  • Logical errors common

  • Poor long-term maintainability

Power Apps does NOT optimize these automatically.

Example

If(
    Form1.Mode = FormMode.View,
    DisplayMode.View,
    If(
        varUserRole = "Manager",
        If(
            Form1.Valid,
            DisplayMode.Edit,
            DisplayMode.Disabled
        ),
        DisplayMode.Disabled
    )
)

4. Switch() — Value-Based Routing (Cleaner & Safer)

Map one expression to multiple possible values.

Switch(
    Expression,
    Case1, Result1,
    Case2, Result2,
    ...
    DefaultResult
)

Example

DisplayMode =
Switch(
    Form1.Mode,
    FormMode.New, DisplayMode.Edit,
    FormMode.Edit,
        If(
            IsBlank(Parent.Default),
            DisplayMode.Edit,
            DisplayMode.Disabled
        ),
    DisplayMode.View
)

5. Match() — Pattern Recognition, Not Branching

Match() evaluates text patterns using Regular Expressions.

  • Format matters

  • Partial matches needed

  • Validation logic required

Match(Text, Pattern [, Options])

IsMatch() Shortcut

IsMatch(Text, Pattern)

Example

IsMatch(
    txtEmployeeId.Text,
    "Test"
)

Conclusion

  • Nested If() statements work, but they quickly reduce readability and maintainability as logic grows. In Power Apps, clear and concise conditions perform better and are easier to support long term.

  • Use If() for simple decisions, Switch() for multiple outcomes driven by one value, and simplify conditions with logical operators whenever possible. Well-structured conditional logic should read like a business rule, not complex code.

Clear logic = better performance, fewer bugs, and scalable Power Apps.