100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Variables in Flows

How to declare, set, and accumulate values in flow-scoped variables, and where they go wrong inside loops.

Control & DataBeginner8 min readJul 10, 2026
Analogies

Declaring and Typing Variables

Every variable in a Power Automate flow must be created with an Initialize Variable action before it can be set or read, and you declare its type up front as String, Integer, Float, Boolean, Array, or Object. Unlike a Compose action's output, a variable can be updated later in the flow with Set Variable, which is what makes variables useful for running totals and accumulated values.

🏏

Cricket analogy: It's like declaring a scoreboard's 'total runs' field at the start of an innings at zero, then updating it after every ball rather than recalculating from scratch each time.

Set, Increment, and Append Actions

Beyond the generic Set Variable action, Power Automate offers Increment Variable for adding a number to an Integer or Float, and Append to Array Variable or Append to String Variable for building up collections or text without manually re-writing the whole value each time. These specialized actions are both clearer to read in the flow designer and slightly cheaper than a Set Variable with a concat() or union() expression.

🏏

Cricket analogy: It's like a scorer using a dedicated 'add four runs' button rather than typing the whole new total by hand after every boundary.

Variable Scope Inside Apply to Each

A variable's scope is the entire flow, not just the loop it happens to be set inside, which is exactly why variables are the standard way to accumulate a result across Apply to Each iterations — for example, summing an Amount field from every row of a table into a RunningTotal variable. A Compose action, by contrast, only ever holds the output of its own single execution and can't accumulate across iterations.

🏏

Cricket analogy: It's like a match's overall run total persisting across every over, not resetting per over, which is exactly why it can track the whole innings.

When Variables Cause Trouble: Concurrency Conflicts

The same flow-wide scope that makes variables useful for accumulation also makes them dangerous inside a concurrent Apply to Each: if twenty iterations run in parallel and each one tries to Increment Variable on the same counter, race conditions can silently drop updates. The fix is either to set Concurrency Control to a Degree of Parallelism of 1, forcing sequential execution, or to avoid shared-state variables in loops altogether and use array-based operations like union() instead.

🏏

Cricket analogy: It's like two scorers updating the same paper scoresheet simultaneously without talking to each other — one's update can overwrite the other's, silently losing a run.

json
[
  {
    "type": "InitializeVariable",
    "inputs": { "name": "RunningTotal", "type": "integer", "value": 0 }
  },
  {
    "type": "IncrementVariable",
    "inputs": {
      "name": "RunningTotal",
      "value": "@items('Apply_to_each')?['Amount']"
    }
  }
]

Initialize every variable your flow will need near the top, even ones you'll only set later — Power Automate requires Initialize Variable to run before any Set/Increment/Append action touches that name, and grouping them makes the flow easier to audit.

Never Increment Variable or Append to Array Variable on the same variable from inside a concurrent Apply to Each — set Degree of Parallelism to 1 first, or you risk silently losing updates to race conditions.

  • Variables must be created with Initialize Variable and typed as String, Integer, Float, Boolean, Array, or Object.
  • Set Variable overwrites a variable's value; Increment/Append actions update it incrementally.
  • A variable's scope is the whole flow, not just the loop it's set inside, which enables cross-iteration accumulation.
  • Compose only ever holds its own single execution's output and cannot accumulate across iterations.
  • Concurrent Apply to Each loops updating a shared variable risk race conditions.
  • Set Degree of Parallelism to 1, or use array operations like union(), to avoid variable race conditions.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PowerAutomateStudyNotes#VariablesInFlows#Variables#Flows#Declaring#Typing#StudyNotes#SkillVeris#ExamPrep