Power Automate Initialize Variable

In this Power Automate Tutorial, we will discuss how to Initialize a Variable on Power Automate. We will see everything on Power Automate Initialize Variable. Also, we will discuss the below topics:

  • Power Automate Variable
  • Power Automate Initialize Variable type
  • How to initialize variable in Power Automate
  • Power Automate Initialize Variable Array
  • Power Automate appending to an Array
  • Power Automate Initialize Variable date
  • Power Automate Initialize Variable Perfoming Operation
  • Power Automate Initialize Variable float
  • Power Automate Initialize empty Variable
  • Power Automate Initialize variable Apply to each
  • Power Automate Initialize Variable boolean
  • Power Automate Initialize Variable in condition

Variable in Power Automate

Before initializing a variable on Power Automate, first, we will know what is variable on Power Automate.

In Power Automate, a variable is just like temporary storage where we can store the data in any data type such as integer, float, boolean, string, array, and object. After initializing the variable, we can use this to perform such tasks:

  • Get or reference the variable’s value
  • Increment or decrement the variable’s by constant value
  • Asign the different value to the variable

Power Automate Initialize Variable type

There are various data types those are provided by Power Automate; such as:

  • String- It is used as text input i.e. hello, SharePoint, etc.
  • Boolean- Here the value can be either true or false.
  • Float- It acepts the numeric data type that has decimal i.e. 45.23, 78.3, etc.
  • Number– It accepts only numerical data type i.e. 60, 25, etc
  • Object- It contains the pair of properties and value that are in JSON format.
  • Array- It is to input as list of objects which must be a similar datatype.

Read SharePoint auto generate column value using Power Automate or Flow

How to initialize variable in Power Automate

Before using a variable in Power Automate, first, we will see how to initialize the variable in Power Automate. For this, follow this step-by-step guide.

Step-1:

Go to Instant cloud flow, then select the trigger to start the flow i.e. Manually trigger a flow.

Power Automate Initialize Variable
Power Automate Initialize Variable

Step-2:

Now we will add an action to initialize the variable i.e. initialize variable. We can find 3 parameters under that action such as:

  • Name– Here we have to give a name to our variable.
  • Type– Here we have to define the data type of the varriable that we want to assign.
  • Value– Here we can give a value either a constant value or a dynamic value.
How to initialize variable on Power Automate
How to initialize variable on Power Automate

Step-3:

Now we will add a compose action to get the output from the input(from variable). But we can’t change the original input in compose.

Microsoft Flow Initialize variable
Microsoft Flow Initialize variable

When we run the flow, we can see the output on Compose:

Initialize Variable on Power Automate
Initialize Variable on Power Automate

This is how to initialize variables with string data types on Power Automate.

Read Save my email attachments to a SharePoint document library Power Automate or Flow

Power Automate Initialize Variable Array

Now we will see how to initialize the variable with the Array data type on Power Automate.

Let’s say we have an array i.e. [Chicago, New York, Los Angeles, Texas, California]. We want to show this array on Power Automate. For this, we will add an action to initialize the variable. And make sure o change the data type as Array.

Power Automate Initialize Variable array
Power Automate Initialize Variable array

After initializing the array, we will add a compose action to retrieve the array on Power Automate.

Initialize Variable array Power Automate
Initialize Variable array Power Automate

We can see the array on the output of the Compose:

Microsoft flow Initialize Variable array
Microsoft flow Initialize Variable array

In the above example, we used strings in an array. Similarly, we can use integer values in an Array:

Initialize Variable array Microsoft Flow
Initialize Variable array Microsoft Flow

We can see the output is also coming as in integer data type.

Power Automate Initialize Variable Array data type
Power Automate Initialize Variable Array data type

This is how to initialize variables with Array data type on Power Automate.

Read PowerApps upload file to SharePoint document library

Power Automate appending to an Array

Now we will see how to append a string on an array by initializing it. For this, we are going to use the string array that we have created previously i.e. [“Chicago”, “New York”, “Los Angeles”, “Texas”, “California”].

Then, we will add the action “Append to array variable” that will append a value on the existing array variable. For example, we want to add a value i.e. Columbus on the existing array( VarArray ).

Power Automate appending to an Array
Power Automate appending to an Array

Now we will add a Compose action to get the output.

Appending to an Array Power Automate
Appending to an Array Power Automate

And we can see the output is coming as:

[“Chicago”, “New York”, “Los Angeles”, “Texas”, “California”, “Columbus”]

Microsoft flow appending to an Array
Microsoft flow appending to an Array

This is how to append to an Array on Microsoft flow.

Read Power Automate Delete all items in SharePoint list

Power Automate Initialize Variable date

In Power Automate, there is no “date” type to initialize the variable on Power Automate. But there is another way to initialize variables for a date on Power Automate flow.

Let’s take an example when we will insert a date it will show the output (date type) by adding the time from the existing date.

To implement this, we will add input as a Date.

Power Automate Initialize Variable date
Power Automate Initialize Variable date

Then we will add an action to initialize the variable. Here we will give a name to the variable and set the type as a string. In value, we will give an expression to adding the time on the given date-time.

addDays(triggerBody()['date'],30)
Initialize Variable date Power Automate
Initialize Variable date Power Automate

We can see if we insert today’s date then it will show the date added by 30 days.

 Initialize Variable date Power Automate flow
Initialize Variable date Power Automate flow

When we will test the flow, it will ask to insert the date. For example, we will insert today’s date i.e. 10/29/2021.

Power Automate Initialize Variable Date type
Power Automate Initialize Variable Date type

Now we will run the flow to see the output(i.e. 2021-10-29 + 30 = 2021-11-28)

Initialize Variable date Microsoft Flow
Initialize Variable date Microsoft Flow

This is how to Initialize Variable dates on Power Automate.

Read Run Flow on a Schedule in Power Automate

Power Automate Initialize Variable Perfoming Operation

In Power Automate, we can perform various operations such as; set, increment, decrement, append on Array string and append on Array integer.

Set Operation on variable

Here we will see how to set a variable on power Automate. For this, first, we will initialize a variable type as Integer.

Power Automate Initialize Variable Performing Operation
Power Automate Initialize Variable Performing Operation

Then we will add another action to set the variable i.e. Set variable. Also, we will set a value to the existing variable(i.e. VarNumber).

Power Automate Initialize Variable and set variable
Power Automate Initialize Variable and set variable

Then we will use Compose action to get the final output.

Power Automate Initialize set Variable
Power Automate Initialize set Variable

We can see the output of VarNumber is updating from 70 to 45.

Microsoft Flow Initialize set Variable
Microsoft Flow Initialize set Variable

This is how to set a variable on Power Automate.

Read Power Automate shared mailbox

Decrement Operation on variable

Now we will see how to decrement a value by initializing a variable on Power Automate. To do this operation we will add an operation “Decrement variable“. There is an option to give a value, that will decrease the value from the original value of the existing variable(i.e. 45).

Power Automate Initialize decrement Variable
Power Automate Initialize decrement Variable

We can see the output is decreased from 45 to 40.

Power Automate Initialize decrement Variable
Power Automate Initialize decrement Variable

This is how to do Power Automate Initialize decrement Variable.

Read How to move files from OneDrive to SharePoint using Power Automate

Increment Operation on variable

Similarly, we can do an increment operation on the variable by using “Increment variable“. Here also, we have to insert a value that will increase the value of the last existing value( i.e. 40).

 Initialize Increment Variable on Power Automate
Initialize Increment Variable on Power Automate

We can see the output is increased from 40 to 55.

Initialize Increment Variable on Power Automate
Initialize Increment Variable on Power Automate

This is how to do Power Automate Initialize Variable Performing Operation.

Read How to convert decimal to whole number in Power Automate

Power Automate Initialize Variable float

Here we will see how to initialize a variable with float data type on Power Automate. For this, first, we will initialize a variable, set the type as the float, and insert a value with decimal places.

Power Automate Initialize Variable float
Power Automate Initialize Variable float

Then we will add a Compose action to get the output as the float.

Power Automate Initialize Variable float
Power Automate Initialize Variable float

And we can see the output coming as float data type:

Initialize Variable float Power Automate
Initialize Variable float Power Automate

This is how to Initialize Variable with float data type on Power Automate.

Also read, Leave Request Approval Flow using Power Automate or Microsoft Flow

Power Automate Initialize empty Variable

In Power Automate, we can initialize a variable having a null or empty value. There is a function named null() used to initialize an empty variable on Power Automate. Now we will see how to create an empty variable on Microsoft flow.

For this, we will add the action “Initialize variable” on the flow. Here we will set the variable name and type. On the value, we will add an expression to create a null value.

null

Then we will use this variable on Compose action to check the output:

Power Automate Initialize empty Variable
Power Automate Initialize empty Variable

We can see there is a null value is created on the output.

Power Automate Initialize empty Variable
Power Automate Initialize empty Variable

We can see the empty string by clicking on the Show raw outputs.

Initialize empty Variable on Microsoft Flow
Initialize empty Variable on Microsoft Flow

This is how to Initialize an empty Variable on Microsoft Flow.

Check out, Power Automate Concatenate String

Power Automate Initialize Variable boolean

Now we will see how to initialize a boolean type variable on Power Automate with a suitable example.

Let’s say if 25 is greater than 20 then it returns true otherwise it returns false. To implement this, the following process is:

Step-1:

On Power Automate, to initialize a variable we will use the action “Initialize variable“. Here we will give a name to our variable, set the type as “boolean” and insert the expression according to our requirement. The expression is:

greaterOrEquals(25,20)
Power Automate Initialize Variable Boolean
Power Automate Initialize Variable Boolean

Step-2:

Then we will add a condition to satisfy our requirements like below:

Initialize Variable Boolean Power Automate
Initialize Variable Boolean Power Automate

The above flow shows that if the VarBoolean is equal to true i.e. 25 > 20, then the “If yes” will execute otherwise the “If no” will execute.

Let’s run the flow to see the result.

How to Initialize a Boolean Variable on Power Automate
How to Initialize a Boolean Variable on Power Automate

As 25 is greater than 20 it executes the true(the IF-yes part) value, otherwise it executes the else(the If no) part.

This is How to Initialize a Boolean Variable on Power Automate.

Also read, Power Automate convert time zone

Power Automate Initialize variable Apply to each

Apply to each is an action, that iterates all the items in a collection as similar as for loop. Now we are going to see how an apply to each loop works with Power Automate.

Step-1:

For this, first, we will create a blank list where the data will update after running the flow. For example, we will create a SharePoint list named “Equipments“.

Power Automate Initialize Variable in apply to each
Power Automate Initialize Variable in apply to each

Step-2:

Now on Power Automate, we will add the action “Initialize variable“. On that, we will give a name to the variable, set the type as Array, and give an array value.

For example, we will use an array having value as:

["Mobile", "TV", "Desktop", "Laptop", "Tab"]
Apply to each control in Power Automate
Apply to each control in Power Automate

Step-3:

Then we will add “Apply to each” from Control action. Here we will add the output of the variable that we initialized i.e. VarEquipments.

Use variable in loop on Power Automate
Use variable in loop on Power Automate

Also, in that action, we will add another action “create item(SharePoint)”. Here it will ask to give the Site address, list name, title. In title, we will put the “current item(apply to each)” from dynamic content.

Initialize variable inside a Apply to Each loop
Initialize variable inside a Apply to Each loop

Now our flow is ready to run. We will save it and test it. After running successfully we can see the records from the array-variable for each item, which is automatically created in our sharePoint list.

Set Variable in Apply To Each Concurrency Control
Set Variable in Apply To Each Concurrency Control

This is how to use Power Automate Initialize Variable in apply to each control.

Read Microsoft flow change true to yes

Power Automate Initialize Variable in condition

Here we will see how to use if-else condition on Power Automate by initializing a variable. For example, we want to show the result of a student whether it is grade A or grade B on the basis of Total mark.

If the total mark is greater than or equal to it will be gradeA otherwise it will be gradeB.

To apply this, on power Automate we will trigger the flow manually, and also, we will use a number field as an integer.

Power Automate Initialize Variable in condition
Power Automate Initialize Variable in condition

Then we will add a Condition(control) action, where we will check conditions as per our requirements. like below:

Power Automate Initialize Variable in if-else condition
Power Automate Initialize Variable in if-else condition

The above flow shows that, if the TotalMark is greater than or equal to 75 then it will execute the If yes part i.e. Grade A. Similarly, if the TotalMark is less than 75 then it will execute the If no part i.e. Grade B. For example, we will insert 65 as TotalMark.

Initialize Variable in condition Power Automate
Initialize Variable in condition Power Automate

This is how to Initialize Variable in condition on Power Automate.

Download Flow

You can also download the flow and test it.

Check out previous Microsoft flow or Power Automate articles:

Conclusion

From this Power Automate Tutorial, we learned all about Initialize variable on Power Automate. Also, we discussed:

  • What is Variable in Power Automate?
  • Discuss the Initialize Variable types on Power Automate?
  • How to initialize variable on Microsoft Flow?
  • How to Initialize arrayVariable on Power Automate?
  • How to appending to an Array on Microsoft Flow?
  • How to Initialize date type Variable on Microsoft Flow?
  • Perfoming Operation by Initialize Variable on Microsoft Flow?
  • How to Initialize float Variable on Power Automate?
  • How to Initialize empty Variable on Microsoft flow?
  • How to Initialize Variable as boolean type on Power Automate?
  • How to use apply to each controller using Variable in Power Automate?
  • Apply a condition by using variable on Power Automate?
>