Power Automate Set Variable [9 Examples]

While working with Power Automate, we will need to use some variables and for that, we may also be required to set variables in Power Automate.

In this Power Automate tutorial, we will discuss the Power automate set variable action with a few examples. And also we will discuss the below points:

  • Power automate set variable
  • Power automate initialize variable vs set variable
  • Power automate set variable to current date
  • Power automate set variable to null
  • Power automate set variable in apply to each
  • Power automate set variable expression
  • Power automate set variable if
  • Power automate set variable from excel
  • Power automate set variable date
  • power automate set variable boolean

Power Automate set variable

Microsoft Flow variables are temporary storage, where we can store the data like content, number, string, etc.

Power Automate or Microsoft Flow set variable action is used to assign a different value to an existing variable.

The Properties of Power Automate Set variable action.

  • Name: For the variable to change <variable name>
  • Value: Value we want to assign to the variable, whereas both have same data type. <new value>

Read Power Automate update SharePoint list increment integer field

Power automate initialize variable vs set variable

Here we will discuss the Power automate initialize variable vs set variable.

Initialize variableSet variable
We can create a variable, declare its data type, and set the initial valueBut in the Set variable, we will use the variable which we have initialized and set the value.
In Initialize variable, variables are declared at the global level, not in the condition, loop, and scopeBut set variables can be used local level, which means we can set the variable with the value in the condition, loop, and scope.

Power Automate set variable to current date

Here we will see how to set variables to the current date in Power Automate.

In Power Automate, select the Manually triggered Flow, then click on Next step.

Microsoft Flow set variable to current date
Microsoft Flow set variable to current date

Select initialize variable action, then provide the variable name and type as a string.

power automate set variable to current date
power automate set variable to current date

Now we can set the variable to the current date, so click on the Next step. Select Set variable action then selects a variable name and set the value with the below expression which returns the current date

utcNow()
power automate set variable to current date
power automate set variable to current date

Now click on Save and run the flow manually, you can see the current date is assigned to a variable.

power automate set variable to current date
power automate set variable to current date

This is an example of a power automate set variable to the current date.

See also  How to Remove line breaks from text in Power Automate?

Read Power Automate wait timer – How to use

Power automate set variable to null

Here we will see how to set variable value to null in Microsoft Flow.

In Power Automate, select the Manually triggered Flow. Then click on the Next step.

power automate set variable to null
power automate set variable to null

Select the Initialize variable action to initialize a variable with a date value. Provide the variable name, then type as string and value with the below expression.

utcNow()
power automate set variable to null
power automate set variable to null

Now to set the above variable value to null, so for this click on Next step and select Set variable action, then select the variable name from the drop-down, and set the value with the below expression

null()
power automate set variable to null
power automate set variable to null

Now click on Save and run the flow manually, now you can see that our first value stored in the variable is set to null().

power automate set variable to null
power automate set variable to null

This is an example of power automate set variable to null.

Read How to move emails to folder after 30 days using Power Automate

Power automate set variable in apply to each

Here we will see how to use set variable action in Apply to each action in Power Automate.

We have a SharePoint list called leaving request, to see how to store email id in the variable to send an email.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

In Power Automate, select the Manually triggered Flow, then click on Next step.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

Select Initialize variable action set the variable name, and type as String.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

Now we will retrieve items from the SharePoint list, so click on the Next step. Select Get items action, and provide site address and list name and set Top count as 10.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

In the Next step, select Apply to each action, and then in the output set the value from dynamic content.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

Now set the variable with the value Email, so click on Next step and then select Set variable action, then select a variable name and in the value set from the dynamic content below screenshot.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

In the next step, we will send an email, so click on the Next step and select Send an Email (V2) action. then provide the To, Subject, and Body fields.

Microsoft flow set variable in apply to each
Microsoft flow set variable in apply to each

Now click on Save and run the Flow manually, and once the flow ran successfully you will get an email.

power automate set variable in apply to each
power automate set variable in apply to each

Now you will get an email in Microsoft outlook.

power automate set variable in apply to each
power automate set variable in apply to each

This is an example of power automate set variable in apply to each.

Read Power Automate list rows present in a table filter query

Power automate set variable expression

Here we will see how to use expression in the set variable expression in Power Automate.

Here we will create a flow to get the name of the parent directory of file( SharePoint Documents). So for this, I have a Folder called General inside Document Library.

Microsoft Flow set variable expression
Microsoft Flow set variable expression

In Power Automate, select the trigger ‘When a File is created (properties only)‘. Then Provide the site address and library name.

power automate set variable expression
power automate set variable expression

Then click on Next step select compose action, and in Input write the below expression:

split(triggerBody()?['{Path}'],'/')

Then Initialize a variable to store the parent folder, so click on the Next step and then select Initialize variable action, then provide the variable name and type as string.

power automate set variable expression
power automate set variable expression

Now click on the Next step, select the compose action. In input write the below expression:

length(outputs('Compose_'))
power automate set variable expression
power automate set variable expression

Click on the Next step and select Set variable, then select the variable name and then in value write the below expression:

outputs('Compose_')[sub(outputs('Compose_2'),2)]
power automate set variable expression
power automate set variable expression

Now click on Save, to run the flow create a file in the folder. So here our parent folder name is General.

power automate set variable expression
power automate set variable expression

This is an example Power Automate set variable expression

See also  How to format a currency column in Power Apps?

Read Power Automate get events into excel

Power automate set variable if

Here we will see how to use if statement in Set variable action using Microsoft Flow.

In Power Automate, select the Manually triggered Flow, then click on Next step.

Microsoft flow set variable if
Microsoft flow set variable if

Select Initialize variable action, then set the variable name and type as integer.

power automate set variable if
power automate set variable if

Now, we will give an input manually so for this we will compose action, then click on compose action, in Input write a day like Monday.

power automate set variable if
power automate set variable if

Now according to input of days name we will return the number and store in the initialized variable. So click on the Next step, and then select Set variable action. Then select variable name from the dropdown list and then in value write the below expression:

If(equals(outputs('Compose'),'Monday'),1,If(equals(outputs('Compose'),'Tuesday'),2,If(equals(outputs('Compose'),'Wednesday'),3,If(equals(outputs('Compose'),'Thursday'),4,If(equals(outputs('Compose'),'Friday'),5,If(equals(outputs('Compose'),'Saturday'),6,If(equals(outputs('Compose'),'Sunday'),0,null)))))))
power automate set variable if
power automate set variable if

Now click on Save and run the flow manually, you can see the result as 6, as our input is Saturday.

power automate set variable if
power automate set variable if

This is an example Power Automate set variable if.

Read Microsoft flow send email based on create date

Power Automate set variable from excel

Here we will see how the set variable action is used from excel data using Microsoft Flow.

So here we have an excel sheet, called Product review, and we want to import that excel table to the SharePoint list automatically.

power automate set variable from excel
power automate set variable from excel

Before we create a Flow we have to create a SharePoint list like the below screenshot.

power automate set variable from excel
power automate set variable from excel

In Power Automate select the manually triggered Flow, then click on Next step.

power automate set variable from excel
power automate set variable from excel

Select Initialize variable action, and then set variable name as ReviewDate, and type as string.

power automate set variable from excel
power automate set variable from excel

Now to get the data from excel, click on the Next step and select ‘List rows present in a table’ action. Then provide the Location, Document Library, File, and table.

power automate set variable from excel
power automate set variable from excel

Next click on the next step and add apply to each action, then set the value.

Inside apply to each action, click on Add an action and then select Set variable action. Now provide the variable name and in value write the below expression.

addDays('1899-12-30',int(item()?['Date']),'yyyy-MM-dd')

Now we will import the excel sheet to SharePoint list. So inside apply to each add another action and select Create item action, now, provide the site address and list name from the dynamic content. Then map the excel value with the SharePoint list field.

power automate set variable from excel
power automate set variable from excel

Now click on Save and run the flow manually, and you can see the SharePoint list get updated.

power automate set variable from excel
power automate set variable from excel

Check out, Power Automate or Microsoft Flow check day of week

See also  How to Patch Dataverse Choice Column in Power Apps

Power automate set variable date

Here we will see an example of power automate set variable date.

In Power Automate select the Manually triggered Flow, then click on Next step.

power automate set variable date
power automate set variable date

Select Initialize variable action, then set the variable name and type as string.

power automate set variable date
power automate set variable date

Now click on the Next step and select the Set variable action, then set the variable name and value write the below expression, which will return the previous date.

addDays(utcNow(),-1)
power automate set variable date
power automate set variable date

Now click on Save and run the Flow you can see the result

power automate set variable date
power automate set variable date

This is an example of power automate set variable date.

Read Power Automate SharePoint Get Items Filter Query + 12 Examples

Power automate set variable boolean

Here we will see how to set variable boolean in Power automate.

We will use the Yes/ No column i.e. Delivered? column of Project Management SharePoint list. If the project is delivered then it will return true, else it will return False.

power automate set variable boolean
power automate set variable boolean

In Power Automate, select the Manually triggered flow, then click on Next step.

power automate set variable boolean
power automate set variable boolean

Select Initialize variable action, then set variable name, type as boolean, and in value set the value false.

power automate set variable boolean
power automate set variable boolean

Now retrieve items from SharePoint list, so click on the Next step and then select Get items action, and then provide the site address and list name.

power automate set variable boolean
power automate set variable boolean

Next we will apply to each items, so click on the Next step, select Apply to each action, then set the value in output.

Inside apply to each, add an action, select the Set variable action, and then set the variable name from the dropdown and in value write the below expression:

bool(item()?['Delivered_x003f_'])
power automate set variable boolean
power automate set variable boolean

Now click on Save and run the flow manually you can see for the second item is delivered so, it returns true.

power automate set variable boolean
power automate set variable boolean

This is an example of Power Automate set variable boolean.

Related Power Automate tutorials:

In this Power Automate tutorial, we learned about Power automate set variable action. And also we will discuss the below points:

  • Power automate initialize variable vs set variable
  • Power automate set variable to current date
  • Power automate set variable to null
  • Power automate set variable in apply to each
  • Power automate set variable expression
  • Power automate set variable if
  • Power automate set variable from excel
  • Power automate set variable date
  • Power automate set variable boolean
>