The switch is a control action designed to find a match for a certain value. It's not a logical statement. It only compares if the value is equal to something and when it finds a match then it takes action on a separate branch.
If you know some other programming languages then condition control action is nothing but switch statements.
For example, if we received an order and the order has different categories like Electronics, Seasonal, and Health. The requirement is that if the category is Electronics then it goes to Expedited Shipping, if it's Seasonal it goes in Cargo and Health goes in DHL.
Creating the Switch action flow in power automate
- Let's get back to the previous condition flow. Click on the New step.
- Select Initialize variable from actions. Create a variable name ShippingMethod of type String. Click on the New step.
- Select Switch (Control) from actions.
- As we are performing actions for Category. Add Category from dynamic content.
- Select Set Variable from actions. For the first case, we have Electronics. Choose ShippingMethod as a variable and enter the value Expediated.
- Similarly, enter values for Seasonal, Health, and Default case. If there is no category matching with the variable value the Default case will be executed.
- Add Compose(Data Operation) from actions. Add ShippingMethod variable from dynamic content. Click on Save.
- Click on Test. Enter the values in Order item, Category, Amount. Click on Run flow.
- Click on Compose to see the Output. Here, it's showing the output as Expediated which is associated with the Electronics category. Similarly, you can do it for other categories as well.
- For default case, if you enter any other category. It will show you the default output.
- Here, it's showing Ground Shipping as our output with the default case.
This was all about Switch control action in Microsoft Power Automate.