In this Power Automate tutorial, we will discuss what is switch case is in Power Automate. We will also see, Power Automate Switch case Multiple conditions with an example.
And also we will discuss the below points:
- Introduction to Power Automate Switch case
- power automate switch limit
- power automate switch case expression
- power automate switch case string
- Power Automate Switch Case Multiple Conditions
Introduction to Power Automate Switch case
In Power Automate, a Switch case action is a control function that allows for expression or variable to change the flow behavior. Where switch case has multiple cases which include different action or block of statement.
Power Automate switch block contains three main components:
- In the Microsoft flow switch action indicating the start of the switch block. Whereas each switch is accompained by an end action indicating the end of the switch block.
- Then within the switch block, each case will take a block of action if the condition is satisfied or true.
- If the condition is not ssatisfied, then it flow will run default case block, if any.
Power automate switch limit
The Power automates switch case is limited to 25 cases. Also, we can create a case in the default case of the first switch. Also, you can even place the two switches underneath each other as two sequential steps, but it will make it harder to under the logic and also harder to debug the flow.
Power automate switch case expression
Here we will see how to automate if the switch case value is null using power automate.
I have created a list in SharePoint Online i.e. Employee Information. In which choice field i.e. Department is not mandatory, therefore it could be left blank.
So when a user adds the information of the employee, according to the department the manager will assign automatically by Power automate.
So, for this, I have created a flow in Power automate. The flow will trigger when an item is created.
Then I run my flow by creating an item in the Employee information list, and I choose the department value as IT. So flow run successfully as case 1 is satisfied.
But now what happens, if you don’t select any choice from the department column and the department field remains empty. Then we might expect that the default case will execute, but it throws the error like below
So, there is one way to solve the problem is to check before the switch if the choice field is set or not and then run the switch only when it is set. In this approach, we will solve the problem then our flow becomes large.
So, we will use the Coalesce function within the Switch but use the choice value inside this function.
Now while creating a new item, if you leave the choice field is null, then this time your flow will return “Unknown”.
Power automate switch case string
Here we will see how to switch between the string based on the condition using Power automate. Let us see an example of Power automate switch case string.
I have created a list in SharePoint list i.e. Employee Information. Here when a user will add employee information, according to the department value manager will assign it automatically by Microsoft Flow.
Steps to update the Employee Information using Power automate.
Step 1: Create a SharePoint List
In SharePoint Online, I have created a SharePoint list called Employee Information having 8 columns with the required column type.
|Title||A single line of text|
|Hire Date||Date and Time|
|DOB||Date and Time|
|SIN||Single Line of Text|
Once your Sharepoint List is created, then we will create a flow in Power automate.
Step 2: Create a Flow in Power automate
Now we will create a flow that will update items in the SharePoint list.
Log in to Power Automate, then click on Create -> Automated Cloud flow.
Next, Provide the flow name, then select the trigger ‘When an item is created. Then click on create.
Step 3: When an item is created
In this step provide the site address and list name in which you want to update the Employee Information.
Step 4: Switch between Multiple string values
Here we have 4 choices in the Department column, so we will create 4 cases based on a single control. The department column contains 4 values i.e. Administrator, IT, HR, and Sales.
So here If the first case is true then it will execute the 1st case else it will check the second case, if the second case is true then it will run, or else it will check the third case, and so on.
So for this Click on the Next step, then select the switch control.
Now we will set the value in which the switch will on or run if the value will not pass then the switch will not run.
So, here we will set the value as Department value
Then set the case1 for Administrator value, if the case1 is true then update item with the assigned manager value (hardcoded).
Now if the case for Administrator return false, next in case 2 set the value for IT. Then if this case for IT is true then update the item For IT.
If the Case IT is False then in a similar way create a case for HR like below. if it is true then it will return the case for HR
At last, if the case for HR is false then it will run the case for sales.
Read Power Automate Create SharePoint List
Step 5: Run the flow
Now add an item in the SharePoint list to trigger the flow and while adding value leave the manager box that will assign automatically.
So here I have added the Employee information, i.e. Salina Gomej and the department is HR
So now you can see the Employee’s manager is assigned automatically.
Also, we can check the flow in Power automate, as the employe department is HR, so we can check the case for HR.
This is an example of a Power automate switch case string.
Read Power Automate Array Variable
Power Automate Switch Case Multiple Conditions
In this Power Automate tutorial, we will discuss the Power Automate Switch case Multiple conditions with an example.
So, here we will create the Microsoft flow which will update items in the SharePoint list automatically based on multiple conditions.
Switch Case Multiple Conditions in Microsoft Flow
Here we will see how to update an item in the Sharepoint list with multiple conditions using a switch case in Microsoft Flow.
I have created a SharePoint task list, when a user will create a task based on the technology column value the person will be assigned automatically to that task.
For example, if a user selects SharePoint technology, then automatically user 2 will be assigned in the Assigned to field.
Similarly, if a user selects MongoDB technology the automatically user 4 will be assigned in the Assigned to field.
For multiple technologies we need multiple conditions, so for this, we will take a switch case.
Also, read, Power Automate update SharePoint list item
Create Power Automate Switch case Multiple condition Steps
Step 1: Create A SharePoint List
In SharePoint Online I have created a SharePoint task list, having 7 columns with the required column type.
|Column Name||Column Type|
|Title||Single Line Of text|
|Description||Multi line of text|
|Start Date||Date and Time|
|Due Date||Date and Time|
|Previous Technology||Single Line of Text|
Once the task list is created in SharePoint, now we can move towards the next step to create a flow in Power Automate.
Step 2: Create a Flow in Power Automate
Now, we will create a flow in Power Automate, which will update the item in the SharePoint list.
- Login to Power automate, then click on Create icon in the navigtion bar, then select Automated Cloud Flow.
Now provide the Flow name, then select a trigger when an item is created or modified.
Step 3: When an item is created or modified
In this step, we will provide the site address and the list name in which you want to update the task.
Step 4: Multiple conditions using Switch case
Here we have four choices in the technology field, for we will create 4 cases/conditions based on a single control.
If the first case is true then it will update the item in the SharePoint Online list else it will check the second condition, if the second condition is true it will update the item otherwise it will check the third case, and so on. And once the condition is satisfied it will terminate.
- Click on the Next Step, then select the Switch control from choose an operation option.
- Now we will set the value in which switch will on or run, if that value will not pass then switch will not run.
- So, here we will set the value as technology value.
- In first case we will assign SharePoint if the technology value is SharePoint then it will run.
- So in this case we will add an action to update the item as well as assign the person to the SharePoint task
- For this, click on the Add an action, then add update item action.
- Then in the Update item for SharePoint, provide the dynamic content to the site address, List name, id, Title, start date, and in assigned to add the Person email(hard coded), whom you want to assign.
- Then in previous technology column is equal to technology value from the dynamic content, so the previous technology column is used to store the previous technology value.
- If the case for SharePoint technology is false then it will go to next case, which is for Python technology.
- To create the next case click on the plus icon present next to the case.
- So set equals to Python.
- Then click on add an action, and select the update item for Python.
- Then provide the information and assigned a person whom you want to assign for Python technology in the updated item for Python. Then provide previous technology is equal to technology value from dynamic content
- Now if the case for Python is false then it will move to the next case i.e. SQL.
- Similarly create the case for SQL and add update item action for Sql.
- And also assign a person email in the update item.
- If the case for SQL is false then it will check the next case i.e. for MongoDB.
- Similarly create a case for MongoDB, and update the item action for MongoDB.
- And assign a person to the MongoDB technology.
If any of the conditions are not true then it will run the default case or it will terminate the switch control.
Once the Flow is ready, we can check the flow, so click on Save, then test the flow manually.
Step 5: Add trigger condition
After saving the flow, you will see the warning, is Popped by Power Automate, because the update item action in the flow would update the item, and as soon as the item is updated, the flow would be trigger again.
For each update item action, it will show the warning.
So to stop this infinite loop trigger we will add a trigger condition i.e when the Technology field value is not equal to the previous technology field value, then only the flow will trigger.
- Click on the more icon in ‘when an item is created or modified’, then click on Setting.
- Scroll down to trigger condition, then click on Add icon to add the trigger condition.
- Then add the below trigger condition. Click on Done.
Step 6: Run the Flow
Now add an item in the SharePoint task list, while assigning value to the field leave blank the Assign to field.
So here I have created a task i.e. “Power Bi Schedule Refresh” and I have assigned the technology as SharePoint.
So now you can see that the person is assigned to the SharePoint technology.
And also in Power automate also we can check the flow, as I have selected the technology as SharePoint, so we will check the condition is true or not.
If the case for SharePoint is true, after that you can check the update item for SharePoint by expanding.
In this Power Automate tutorial, we learned, how to apply multiple conditions using switch cases in the Microsoft Flow.
Related Power Automate Tutorials:
- Unable to process template language expressions in action Power Automate
- Convert SharePoint document to PDF using Power Automate
- Microsoft Flow or PowerAutomate Example: Save my email attachments to a SharePoint document library
- Microsoft Flow or PowerAutomate Example: Send a customized email when a new file is added
- Send an Email when Item added in a SharePoint list using Microsoft Flow
- Failed to create connection for connection id while setting up push notification in Microsoft Flow in Office 365
- Trigger Conditions in Power Automate
- Power Automate send an email with an attachment from SharePoint
- Power Automate Replace
In this Power automate tutorial, we learned about Power automate switch case. And how to apply multiple conditions using switch cases in the Microsoft Flow or Power Automate. And also we discuss the below points:
- Introduction to Power Automate Switch case
- Power automate switch limit
- Power automate switch case expression
- Power automate switch case string
- Power Automate Switch Case Multiple Conditions
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.