Variables in Power Automate Explained: Complete Guide

Suresh Girinathuni9 min read
Variables in Power Automate Explained: Complete Guide

A practical guide to variables in Power Automate: variable types, initialize vs set, append string and array variables, counters, object variables, expressions, loops, concurrency, examples, and best practices.

Variables in Power Automate help you store, update, and reuse values while a cloud flow is running. They are useful when a flow needs to remember a status, build an email summary, count records, collect items in an array, or store structured data for later actions.

If you are new to Power Automate, variables can feel confusing because they look similar to dynamic content, Compose actions, expressions, and connector outputs. The simple rule is this: use a variable when the value needs to change during the flow run. If the value does not need to change, a Compose action or direct expression is often cleaner.

What is a variable in Power Automate?

A variable is a named container for a temporary value. The flow creates the variable, stores a value in it, and then other actions can read or update that value later in the same run.

Power Automate variable actions: initialize, set, append, increment, decrement, and reference values

For example, an approval flow can initialize a variable named varApprovalStatus with the value Pending. After the approval response comes back, the flow can set that same variable to Approved or Rejected. Later, the flow can use the variable in a SharePoint update, Teams message, or email notification.

When should you use variables?

Use variables when a flow needs to carry changing state across steps. This is common in approval flows, loops, reporting flows, exception handling, and flows that build summaries.

  • Store an approval status such as Pending, Approved, or Rejected.
  • Count how many records were processed successfully.
  • Build a multiline email body while looping through records.
  • Collect selected SharePoint items into an array.
  • Store a reusable object with employee, request, or customer details.
  • Track error messages before sending a final notification.

When should you avoid variables?

Do not add variables just because they make a flow look familiar to traditional programming. Extra variables increase the number of actions and can make the flow harder to read. If you only need a value once, use dynamic content directly. If you only need to calculate a value once, use Compose.

NeedBetter option
Use a connector output onceDynamic content
Calculate a value onceCompose
Change a value during the runVariable
Store a setting across environmentsEnvironment variable
Save a value after the flow endsSharePoint, Dataverse, SQL, Excel, or another data source

Power Automate variable types

Power Automate supports six variable types. Choose the type based on the kind of value you need to store and how later actions will use it.

TypeUse it forExample
StringText values, names, statuses, email bodies, messagesApproved
IntegerWhole numbers and counters10
FloatDecimal numbers145.75
BooleanTrue or false decisionstrue
ArrayA list of values or objectsApproved items
ObjectStructured JSON dataEmployee details

How to initialize a variable

The Initialize variable action creates the variable. You give it a name, choose a type, and optionally set the starting value. A good habit is to initialize variables near the top of the flow, after the trigger and before conditions or loops that need them.

  1. Add a new action.
  2. Search for Initialize variable.
  3. Enter a clear name, such as varApprovalStatus.
  4. Choose the type, such as String, Integer, Boolean, Array, or Object.
  5. Enter the initial value if the flow needs one.
Screenshot suggestion: show an Initialize variable action with Name set to varApprovalStatus, Type set to String, and Value set to Pending.

Microsoft documentation notes that variables are declared at the global level in a cloud flow, not inside scopes, conditions, or loops. Initialize the variable first, then update it later.

Variable naming best practices

Use names that explain the purpose and type. Consistent naming makes a flow much easier to maintain after several months.

PrefixMeaningExample
varGeneral variablevarApprovalStatus
strString valuestrEmailBody
intInteger valueintApprovedCount
boolBoolean valueboolIsApproved
arrArray valuearrApprovedItems
objObject valueobjEmployee

How to set a variable

The Set variable action replaces the current value of an existing variable. It does not create a variable. The variable must already be initialized earlier in the flow.

In an approval flow, the sequence might look like this:

  1. Trigger: when a SharePoint item is created.
  2. Initialize varApprovalStatus with Pending.
  3. Start and wait for an approval.
  4. Add a condition that checks the approval outcome.
  5. If approved, set varApprovalStatus to Approved.
  6. If rejected, set varApprovalStatus to Rejected.
  7. Use the variable in an update item action and email notification.

Initialize variable vs Set variable

ActionPurposeWhen to use
Initialize variableCreates the variable and defines the typeOnce near the beginning of the flow
Set variableReplaces the value of an existing variableAfter a condition, approval response, calculation, or lookup

Append to string variable

The Append to string variable action adds text to the end of an existing string variable. It is useful for building email summaries, log messages, approval comments, and report sections.

concat(
  'Employee: ', items('Apply_to_each')?['EmployeeName'], '
',
  'Department: ', items('Apply_to_each')?['Department'], '
',
  'Status: ', variables('varApprovalStatus'), '

'
)

Initialize the string variable with an empty value first. Then append a section inside the loop for each item.

Append to array variable

The Append to array variable action adds a new item to an existing array. Use this when you need to collect records and process them later.

{
  "Title": "@{items('Apply_to_each')?['Title']}",
  "Status": "@{items('Apply_to_each')?['Status']}",
  "Approver": "@{items('Apply_to_each')?['Approver']}"
}

After the loop, you can use expressions such as length(variables('arrApprovedItems')) to count the collected items, or create an HTML table from the array for an email.

Increment and decrement variable

The Increment variable action increases an integer or float variable. The Decrement variable action decreases it. These actions are useful for counters, totals, retries, remaining capacity, or simple scoring.

Example: initialize intApprovedCount as an integer with value 0. Inside an Apply to each loop, if the item status is Approved, increment the variable by 1.

Object variables

An object variable stores structured JSON data. This is useful when you want related values to travel together instead of creating many separate variables.

{
  "Name": "Suresh",
  "Department": "IT",
  "IsApproved": true
}

You can read a property with an expression such as variables('objEmployee')?['Department'].

Using variables in Apply to each

Variables are often updated inside Apply to each loops. The common pattern is to initialize the variable before the loop, update it inside the loop, and use the final value after the loop.

Be careful with concurrency. If several loop iterations update the same variable at the same time, the final value can be unreliable. For predictable results, keep the loop sequential when updating shared variables, or redesign the flow so each iteration does not write to the same variable.

Variables vs Compose vs dynamic content vs environment variables

FeatureBest forChanges during run?
Dynamic contentUsing outputs from a trigger or actionNo, it is an action output
ComposeCalculating or formatting a value onceNo
VariableChanging a value during the same flow runYes
Environment variableConfiguration values across environmentsUsually no during a run
External data sourcePersisting values after the runYes, if updated

Useful expressions with variables

Variables become more powerful when combined with expressions. Here are common examples:

variables('varApprovalStatus')
equals(variables('varApprovalStatus'), 'Approved')
if(equals(variables('boolIsApproved'), true), 'Approved', 'Rejected')
concat('Total approved: ', string(variables('intApprovedCount')))
empty(variables('arrRecipients'))
length(variables('arrApprovedItems'))

Use expressions in conditions, Compose actions, email bodies, update item fields, and Teams messages when you need more control than basic dynamic content.

Real-world example: SharePoint leave request approval

Imagine a SharePoint list named Leave Requests. When an employee submits a request, Power Automate sends it for approval and updates the list item with the final status.

  1. Trigger: When an item is created in SharePoint.
  2. Initialize varApprovalStatus as String with Pending.
  3. Initialize varApprovalComments as String with an empty value.
  4. Start and wait for an approval.
  5. Condition: check whether the approval outcome is Approve.
  6. Set varApprovalStatus to Approved or Rejected.
  7. Append the approver comments to varApprovalComments.
  8. Update the SharePoint item with status and comments.
  9. Send an email to the employee with the final result.

Best practices

  1. Initialize variables near the start of the flow.
  2. Use clear names that explain the business purpose.
  3. Choose the correct variable type from the beginning.
  4. Use Compose instead of a variable when the value does not change.
  5. Keep variable updates easy to follow.
  6. Avoid updating the same variable from parallel branches unless you understand the impact.
  7. Run Apply to each sequentially when shared variable order matters.
  8. Use array variables for collections, not long strings that are hard to parse later.
  9. Use object variables for grouped data such as employee or request details.
  10. Do not store secrets in plain variables.
  11. Save important final values to a data source if they must persist after the run.
  12. Use scopes to organize related variable logic.
  13. Test with empty, single-item, and multi-item data.
  14. Add comments only where the flow logic is not obvious.

Common mistakes

  1. Trying to initialize a variable inside a loop or condition.
  2. Using Set variable before the variable is initialized.
  3. Choosing String when the flow needs an Array or Object.
  4. Using variables for every value even when Compose is enough.
  5. Updating a shared variable inside a parallel Apply to each loop.
  6. Forgetting that variables disappear after the flow run ends.
  7. Building large text values without line breaks or formatting.
  8. Appending malformed JSON to an array variable.
  9. Using unclear names such as var1 or temp.
  10. Not testing empty arrays or null values before using expressions.

Useful Microsoft resources

For deeper product documentation, review store and manage values by using variables, use expressions in conditions, Power Automate expression cookbook, parallel execution guidance, and Power Automate limits and action guidance.

Conclusion

Variables are one of the most practical features in Power Automate when a flow needs to remember and update information during a run. Start with the correct type, initialize early, update carefully, and avoid shared variable updates in parallel loops. For values that do not change, use Compose or dynamic content. For values that must survive after the run, save them to a real data source.

Call to action

Follow nextM365 for practical Microsoft 365 and Power Platform tutorials. Subscribe on YouTube and follow me on LinkedIn for hands-on guides.

Next tutorial: Power Automate Conditions and Expressions Explained


Keywords: Variables in Power Automate, Power Automate Variables, Initialize Variable, Set Variable, Append to String Variable, Append to Array Variable, Increment Variable, Decrement Variable, Power Automate Expressions, Apply to Each Variables.

Share this:

#Variables in Power Automate#Power Automate Variables#Initialize Variable#Set Variable#Append to Array Variable#Append to String Variable#Power Automate Expressions#Apply to Each#Power Automate Beginner Guide#Microsoft Power Platform

Frequently asked questions

What are variables in Power Automate?

Variables in Power Automate store values during a cloud flow run. A variable can hold text, numbers, true or false values, arrays, or objects, and the flow can update or reuse that value in later actions.

How do I initialize a variable in Power Automate?

Use the Initialize variable action, provide a variable name, choose the type, and optionally provide an initial value. Initialize variables near the beginning of the flow before using them.

What is the difference between Initialize variable and Set variable?

Initialize variable creates the variable and defines its type. Set variable changes the value of an existing variable later in the flow.

What variable types are available in Power Automate?

Power Automate supports integer, float, boolean, string, array, and object variables.

When should I use Append to string variable?

Use Append to string variable when you need to build text over time, such as an email summary, log message, approval comment history, or report body.

When should I use Append to array variable?

Use Append to array variable when you need to collect multiple items during a flow, such as approved records, email recipients, error details, or rows for a later table.

Can I initialize a variable inside an Apply to each loop?

No. Microsoft documentation states that variables are declared at the global level in a cloud flow. Initialize the variable before the loop, then update it inside the loop if needed.

Are variables safe to use inside parallel Apply to each loops?

Be careful. If multiple loop iterations update the same variable in parallel, results can be unpredictable. For predictable variable updates, run the loop sequentially or use a different design.

Should I use Compose or a variable in Power Automate?

Use Compose when you only need to calculate or hold a value once. Use a variable when the value must change during the flow.

Do Power Automate variables persist after the flow finishes?

No. Variables are temporary for the current flow run. To keep values after the run, save them to SharePoint, Dataverse, Excel, SQL, or another data source.

Learn Microsoft 365 with new tutorials every week

Subscribe on YouTube and follow on LinkedIn for hands-on Power Platform, SharePoint, Copilot Studio, and Microsoft 365 guides.

Related articles