Introduction

Evaluation of a variable against multiple values is common in Power Apps for a variety of scenarios, including navigation, visibility control, validations, filtering, and the execution of specific actions.

Multiple OR (||) conditions are typically used to accomplish this, which can make the code repetitive and more difficult to read as the number of conditions increases.

Power Apps in operator makes it easier to check a value against a list in a way that is easier to understand and maintain. When multiple value comparisons are required, this method can be used in a variety of use cases to help keep formulas clean, scalable, and simple to manage.

Traditional Approach (Ex: Navigation)

If(
    gblTabID= 1 || gblTabID= 2 || gblTabID = 3,
    Navigate(screen1),
    gblTabID= 4 || gblTabID= 5 || gblTabID= 6,
    Navigate(screen2),
    gblTabID = 7 || gblTabID = 8,
    Navigate(screen3)
);

Issues with this approach

Why is this superior?

Optimized Approach

Using the 'in' operator simplifies the logic by allowing you to compare a single value against a collection (array) of values, rather than writing multiple OR conditions.

//Optimsed Version 1
If(
 gblTabID in [1,2,3],
 Navigate(screen1),
 gblTabID in [4,5,6],
 Navigate(screen2),
 gblTabID in [7,8],
 Navigate(screen3)
);

// Optimsed Version2

Navigate(
    Switch(
        true,
        gblTabID in [1,2,3], screen1,
        gblTabID in [4,5,6], screen2,
        gblTabID in [7,8],  screen3
    )
)

Explanation

Conclusion

In Power Apps, a clean and effective method for handling multiple value comparisons is to use the in operator with arrays. Instead of repeating OR (||) conditions, values can be grouped into arrays like [1,2,9], making the logic more structured and easier to read.

This method can be used in a variety of situations, including visibility control, validations, filtering, and other forms of conditional logic, and it is not limited to navigation. By leveraging arrays with the in operator, formulas become more scalable, maintainable, and easier to update as requirements grow.