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
Level: Powered On

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

Level: Powered On

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

Level: Powered On

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

Level: Powered On

@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 Staff
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.