web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Is there a possibility...
Power Apps
Answered

Is there a possibility of having a local variable or anything close to a local variable?

(0) ShareShare
ReportReport
Posted on by 14

I am trying extract information from object dynamically based on a {variableName} i.e. "Material Information 1", "Material Information 2" ... "Material Information {variableName}"
At the end of each loop, variableName will be variableName+1

 

The concurrent in 'Apply to Each' is registering the global variable {variableName} so some actions are affected by the variable.

 

Is there a possibility of having a local variable to the loop or anything close to a local variable?
so that when we are performing any action on it, it would execute properly on each input in apply to each.

I have the same question (0)
  • cchannon Profile Picture
    4,702 Moderator on at

    In PowerAutomate, You can only declare variables outside loops, but then you can manipulate them within the loop. So just add an "Initialize a Variable" step outside your loop to create the var, then handle its value inside the loop, including a value initialization at the start of each loop and it will operate just as though it was declared within the loop. Something like: 

     

    • Initialize Var "myVar" == "initialized";
    • Apply To Each:
      • Set Variable Value "myVar" = "";
      • Do stuff
  • Jhmiah Profile Picture
    14 on at

    Thanks for the reply. However, I believe that when we set variable, it is changing the global variable which will interfere with the other concurrent operations.
    i.e.
    lets say there are n=50 concurrency, inside Apply to each (n=1), there is a 'Do Until' that references x(x=1). At the end of 'Do Until', there will be a increment variable (x=x+1), so NOW x=2.
    because of latency, lets say n=14 is running later, inside apply to each (n=1), it is using the global variable x=2 that was set by ApplyToEach(n=1). Therefore it skipped n=1.

     

    Is this a limitation in Power Automate?

  • Verified answer
    cchannon Profile Picture
    4,702 Moderator on at

    Ah, I see what you mean now. Yeah, in that case you have two choices for handling this:

    • Set the max concurrency for the Apply To Each to 1 (screenshot below)
      cchannon_0-1634157023516.png

       

    • Create your loop as a child flow and call it from the flow you're in. That will let you initialize a loop-specific var inside the child flow.

     

  • RajYRaman Profile Picture
    270 on at

    @Jhmiah- If all you need is an iteration variable that increments by one after every iteration, you can use iterationIndexes. Along with concurrency of 20, it will give you better performance.

     

    https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#iterationIndexes

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 400 Most Valuable Professional

#2
11manish Profile Picture

11manish 141 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard