How to Set Variable Based on Condition in Power Automate

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:
Power Automate Set Variable Based on Condition
Power Automate Set Variable Based on Condition
  • 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‘.
Power Automate Set Variable Based on Condition example
Power Automate Set Variable Based on Condition example
  • 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:
Example to Set Variable Based on Condition in Power Automate
Example to Set Variable Based on Condition in Power Automate
  • Select +new step, add compose action to see the set variable action value, and pass the variable value as the input value.
Example to Set Variable Based on Condition in the Power Automate
Example to Set Variable Based on Condition in the Power Automate
  • 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.
Test Power Automate
Test Power Automate
  • As the Flow was run successfully, we can see the result in compose action that displays the set variable value.
Example of Set Variable Based on Condition in Power Automate
Example of Set Variable Based on Condition in Power Automate
  • In the same way, we will try to execute the else value by changing the condition value as highlighted below:
Set Variable Based on Condition in Power Automate
Set Variable Based on Condition in Power Automate
  • Now save and run the Power Automate flow, and we can see the result in compose action that displays the set variable value.
Example of Set Variable Based on Condition in the Power Automate
Example of Set Variable Based on Condition in the Power Automate

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.
Set Variable Based on the Condition
Set Variable Based on the Condition
  • 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.
Set Variable Based on the Condition in Power Automate
Set Variable Based on the Condition in Power Automate
  • Select + New step, add a Compose action to see the set variable action value, and pass the variable value as the input value.
Example to Set Variable Based on the Condition in Power Automate
Example to Set Variable Based on the Condition in Power Automate
  • Click on the Save & Test option as displayed below: Once the flow has been saved, select the RunFlow option.
Run Power Automate flow
Run Power Automate flow
  • As the Flow was run successfully, we can see the result in compose action that displays the set variable value.
Set Variable Based on Condition in the Power Automate flow
Set Variable Based on Condition in the Power Automate flow
  • 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.
Set Variable Based on the Condition in Power Automate flow
Set Variable Based on the Condition in Power Automate flow
  • 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:
Power Automate Set Variable Based on Condition in flow
Power Automate Set Variable Based on Condition in flow

This is how to set variables inside Power Automate’s switch action.

Furthermore, you may like some more Power Automate and SharePoint tutorials:

In this Power Automate Tutorial, we have discussed How to set variables based on conditions in Power Automate with different examples.