How to Set Variable Based on Condition in Power Automate? [With Various Examples]

In this Power Automate Tutorial, we will discuss how to set variable based on condition in Power Automate using different examples.

Set Variable Based on Condition in Power Automate

Using Power Automate, let us see how to set a variable based on condition.

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, log in 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 the Create option as highlighted below:
Failed to get web title Access denied
  • Now, we will initialize a string variable. To do 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
  • 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
  • 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
  • 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.
sharepoint online office 365 disable search in list
Test Power Automate
  • As the Flow was run successfully, we can see the result in the compose action that displays the set variable value.
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:
sharepoint 2013 workflow email link to document
  • Now save and run the Power Automate flow, and we can see the result in the compose action, which displays the set variable value.
Example of Set Variable Based on Condition in the Power Automate

This is how to set variables based on conditions using Power Automate.

Example:2

In this example, we will see how to set variables inside the Power Automate 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. Add +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.
  • The screenshot below shows that I have passed the Product Value as VTT, as highlighted.
Set Variable Based on the Condition
  • Now, select the + New step and add the switch control action. If the product value matches in the case section, we will set the variable value to true; otherwise, we will set the variable value to false for the default section.
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
  • Click on the Save & Test option below. Once the flow has been saved, select the RunFlow option. As the Flow was run successfully, we can see the result in the compose action, which displays the set variable value.
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
  • 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

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

Furthermore, you may like some more Power Automate tutorials:

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

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…