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.
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.
| Need | Better option |
|---|---|
| Use a connector output once | Dynamic content |
| Calculate a value once | Compose |
| Change a value during the run | Variable |
| Store a setting across environments | Environment variable |
| Save a value after the flow ends | SharePoint, 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.
| Type | Use it for | Example |
|---|---|---|
| String | Text values, names, statuses, email bodies, messages | Approved |
| Integer | Whole numbers and counters | 10 |
| Float | Decimal numbers | 145.75 |
| Boolean | True or false decisions | true |
| Array | A list of values or objects | Approved items |
| Object | Structured JSON data | Employee 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.
- Add a new action.
- Search for Initialize variable.
- Enter a clear name, such as
varApprovalStatus. - Choose the type, such as String, Integer, Boolean, Array, or Object.
- 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.
| Prefix | Meaning | Example |
|---|---|---|
| var | General variable | varApprovalStatus |
| str | String value | strEmailBody |
| int | Integer value | intApprovedCount |
| bool | Boolean value | boolIsApproved |
| arr | Array value | arrApprovedItems |
| obj | Object value | objEmployee |
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:
- Trigger: when a SharePoint item is created.
- Initialize
varApprovalStatuswithPending. - Start and wait for an approval.
- Add a condition that checks the approval outcome.
- If approved, set
varApprovalStatustoApproved. - If rejected, set
varApprovalStatustoRejected. - Use the variable in an update item action and email notification.
Initialize variable vs Set variable
| Action | Purpose | When to use |
|---|---|---|
| Initialize variable | Creates the variable and defines the type | Once near the beginning of the flow |
| Set variable | Replaces the value of an existing variable | After 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
| Feature | Best for | Changes during run? |
|---|---|---|
| Dynamic content | Using outputs from a trigger or action | No, it is an action output |
| Compose | Calculating or formatting a value once | No |
| Variable | Changing a value during the same flow run | Yes |
| Environment variable | Configuration values across environments | Usually no during a run |
| External data source | Persisting values after the run | Yes, 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.
- Trigger: When an item is created in SharePoint.
- Initialize
varApprovalStatusas String withPending. - Initialize
varApprovalCommentsas String with an empty value. - Start and wait for an approval.
- Condition: check whether the approval outcome is Approve.
- Set
varApprovalStatusto Approved or Rejected. - Append the approver comments to
varApprovalComments. - Update the SharePoint item with status and comments.
- Send an email to the employee with the final result.
Best practices
- Initialize variables near the start of the flow.
- Use clear names that explain the business purpose.
- Choose the correct variable type from the beginning.
- Use Compose instead of a variable when the value does not change.
- Keep variable updates easy to follow.
- Avoid updating the same variable from parallel branches unless you understand the impact.
- Run Apply to each sequentially when shared variable order matters.
- Use array variables for collections, not long strings that are hard to parse later.
- Use object variables for grouped data such as employee or request details.
- Do not store secrets in plain variables.
- Save important final values to a data source if they must persist after the run.
- Use scopes to organize related variable logic.
- Test with empty, single-item, and multi-item data.
- Add comments only where the flow logic is not obvious.
Common mistakes
- Trying to initialize a variable inside a loop or condition.
- Using Set variable before the variable is initialized.
- Choosing String when the flow needs an Array or Object.
- Using variables for every value even when Compose is enough.
- Updating a shared variable inside a parallel Apply to each loop.
- Forgetting that variables disappear after the flow run ends.
- Building large text values without line breaks or formatting.
- Appending malformed JSON to an array variable.
- Using unclear names such as
var1ortemp. - 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:
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
- Condition vs Switch in Power Automate: Complete GuideA practical beginner-to-intermediate guide to choosing between Condition and Switch actions in Power Automate, with examples, expressions, performance notes, best practices, mistakes, FAQ, schema, and screenshot placeholders.
- Power Automate Flow Types Explained — and How to Build Your First Cloud FlowA beginner-friendly guide to Power Automate: the three flow types (cloud, desktop and generative actions), the three ways cloud flows trigger (automated, instant, scheduled), and a step-by-step walkthrough to build, test and run your first scheduled cloud flow — a monthly newsletter — without Copilot.