cancel
Showing results for 
Search instead for 
Did you mean: 

Switch Case 'contains'

Add the capability to use 'contains' and not just 'equals' with Switch Case.

Status: Declined

We don't have any plans to change (or add to) the behavior of Switch Case. Switch case is a common programming concept, as as best as we can tell, each branch is always about each Case equaling a value. This type of scenario can already be accomplished today in 2 ways though:

 

1. You can use nested conditions -- in each condition you can evaluate using whatever expression you'd like.

2. You can use nested if() expressions inside the Switch On.

 

Personally, I would recommend #2 as that keeps your flow clean - rather than nested conditions which can be difficult to work with. If you had 3 cases it would look something like:

 

if(

    or(contains(variables('foo'), 'good'), contains(variables('foo'), 'great')),

    'GoodCase',

    if(

        contains(variables('foo'), 'bad'),

        'BadCase',

        if(contains('variables'), 'ok'), 'NeutralCase', 'DefaultCase')

    )

)

 

One other thing I'd like to point out is that this approach also gives you much more flexibility than you could ever had if we added contains() to switch case -- for example, you could go down a branch if a string contained one string OR another string.

Comments
New Member

Agree - we need much more granularity with the switch case construct.

Regular Visitor

Very Much Needed. Otherwise it is an *interesting* exercise with nested if statments, and embedded contains

Frequent Visitor

Agreed!!! Can't complete my task to check for blank cells in column 

Advocate I

@v-yuazh-msft Is this something that the Flow team would look to implement? It would be incredibly useful or a workaround would be much appreciated.

Power Automate
Status changed to: Declined

We don't have any plans to change (or add to) the behavior of Switch Case. Switch case is a common programming concept, as as best as we can tell, each branch is always about each Case equaling a value. This type of scenario can already be accomplished today in 2 ways though:

 

1. You can use nested conditions -- in each condition you can evaluate using whatever expression you'd like.

2. You can use nested if() expressions inside the Switch On.

 

Personally, I would recommend #2 as that keeps your flow clean - rather than nested conditions which can be difficult to work with. If you had 3 cases it would look something like:

 

if(

    or(contains(variables('foo'), 'good'), contains(variables('foo'), 'great')),

    'GoodCase',

    if(

        contains(variables('foo'), 'bad'),

        'BadCase',

        if(contains('variables'), 'ok'), 'NeutralCase', 'DefaultCase')

    )

)

 

One other thing I'd like to point out is that this approach also gives you much more flexibility than you could ever had if we added contains() to switch case -- for example, you could go down a branch if a string contained one string OR another string.

Super User

Nesting is very nesting intensive and really makes it difficult to setup and bloats the logic.

Regular Visitor

The sense of switch case is that you don't have to use nested if's. At the moment switch case is pretty much worthless. 😞