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 variable | Set variable |
---|---|
We can create a variable, declare its data type, and set the initial value | But 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 scope | But 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.
Select initialize variable action, then provide the variable name and type as a string.
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()
Now click on Save and run the flow manually, you can see the current date is assigned to a variable.
This is an example of a power automate set variable to the current date.
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.
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()
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()
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().
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.
In Power Automate, select the Manually triggered Flow, then click on Next step.
Select Initialize variable action set the variable name, and type as String.
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.
In the Next step, select Apply to each action, and then in the output set the value from dynamic content.
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.
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.
Now click on Save and run the Flow manually, and once the flow ran successfully you will get an email.
Now you will get an email in Microsoft outlook.
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.
In Power Automate, select the trigger ‘When a File is created (properties only)‘. Then Provide the site address and library name.
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.
Now click on the Next step, select the compose action. In input write the below expression:
length(outputs('Compose_'))
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)]
Now click on Save, to run the flow create a file in the folder. So here our parent folder name is General.
This is an example Power Automate set variable expression
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.
Select Initialize variable action, then set the variable name and type as integer.
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.
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)))))))
Now click on Save and run the flow manually, you can see the result as 6, as our input is Saturday.
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.
Before we create a Flow we have to create a SharePoint list like the below screenshot.
In Power Automate select the manually triggered Flow, then click on Next step.
Select Initialize variable action, and then set variable name as ReviewDate, and type as string.
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.
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.
Now click on Save and run the flow manually, and you can see the SharePoint list get updated.
Check out, Power Automate or Microsoft Flow check day of week
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.
Select Initialize variable action, then set the variable name and type as string.
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)
Now click on Save and run the Flow you can see the result
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.
In Power Automate, select the Manually triggered flow, then click on Next step.
Select Initialize variable action, then set variable name, type as boolean, and in value set the value false.
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.
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_'])
Now click on Save and run the flow manually you can see for the second item is delivered so, it returns true.
This is an example of Power Automate set variable boolean.
Related Power Automate tutorials:
- Power Automate send email to SharePoint group
- Power Automate remove characters from a string
- Power Automate Array Variable
- Power Automate export SharePoint list to excel and send an email
- Power Automate send email based on form response
- Power automate split string into an array with examples
- How to call a flow from another flow in Power Automate
- Power Automate create table
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
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.