In this Power Automate Tutorial, we will discuss How to set variable based on condition in Power Automate with different examples.
Power Automate Set Variable Based on Condition
Let us see how to set a variable based on condition using Power Automate.
Example-1
In this example, we will see how to initialize a string variable and set the string value based on the condition using the set variable action in Power Automate.
- Initially Login to Power Automate, and click on the + Create -> Instant Cloud Flow.
- Then Build an Instant Cloud Flow window will appear, enter the Flow name, select the trigger ‘Manually trigger‘ and then Click on Create option as highlighted below:

- Now we will initialize a string variable, for that, select the ‘+New Step‘ option, provide the variable name, and choose the variable type as ‘String‘.

- Then click on +New Step, to add the condition action, if the condition matches the initialized variable then set the variable as true, else set the variable as false as highlighted below:

- Select +new step, add compose action to see the set variable action value, and pass the variable value as the input value.

- To test the flow, Choose Manually and Select the Save & Test option as displayed below: Once the flow has been saved, select the RunFlow option.

- As the Flow was run successfully, we can see the result in compose action that displays the set variable value.

- In the same way, we will try to execute the else value by changing the condition value as highlighted below:

- Now save and run the Power Automate flow, and we can see the result in compose action that displays the set variable value.

This is how to set variables based on conditions using Power Automate.
Also, Read: Power Automate Set Variable Action [With Examples]
Example:2
In this example, we will see how to set variables inside Power Automate’s switch action.
Recently, I was working on Power Automate where I was supposed to set a variable for further use based on the value of an option set field in an entity, here we will discuss it in detail.
- So, for this, I have created an instant cloud flow in Power Automate. And +New step to initialize the variable which is of string data type and manually pass the Product value that you have to check with the condition.
- In the below screenshot, you can see that I have passed the Product Value as VTT as highlighted.

- Now, select + New step and add the switch control action, and if the product value matches in the case section we will set the variable as true, else we will set the variable value as false for the default section.

- Select + New step, add a Compose action to see the set variable action value, and pass the variable value as the input value.

- Click on the Save & Test option as displayed below: Once the flow has been saved, select the RunFlow option.

- As the Flow was run successfully, we can see the result in compose action that displays the set variable value.

- In the same way, we will change the Product value as Velo in the Switch control action as shown below:
- If the condition Product value doesn’t match the initialized product value then it executes the default section in the switch control action in Power Automate.

- Save the changes made in the flow and run the flow. Once the flow has been run we can see the expected result value as displayed below:

This is how to set variables inside Power Automate’s switch action.
Furthermore, you may like some more Power Automate and SharePoint tutorials:
- How to Get Current Date in Power Automate
- How to Initialize Variable Condition using Power Automate
- How to Use Power Automate Delay Action
- Power Automate Condition if a String is Empty
- How to Add a Thumbnail View in SharePoint Online Document Library
In this Power Automate Tutorial, we have discussed How to set variables based on conditions in Power Automate with different examples.
Bijay Kumar Sahoo is a highly accomplished professional with over 15 years of experience in the field of SharePoint and related technologies. He has been recognized as a Microsoft MVP (Most Valuable Professional) more than 9 times, starting from April 2014, for his exceptional contributions to the SharePoint community. Bijay is also a prolific author, having written two books on SharePoint – “Microsoft Power Platform – A Deep Dive” and “SharePoint Online Modern Experience Practical Guide“. His deep insights into SharePoint are also shared on his popular YouTube channel EnjoySharePoint where he teaches SharePoint to a global audience (From various countries like the United States of America, Canada, the United Kingdom, Australia, New Zealand, etc). Read more…