Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
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.

  • RajYRaman Profile Picture
    270 on at
    Re: Is there a possibility of having a local variable or anything close to a local variable?

    @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

     

  • Verified answer
    cchannon Profile Picture
    4,702 Super User 2025 Season 1 on at
    Re: Is there a possibility of having a local variable or anything close to a local variable?

    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.

     

  • Jhmiah Profile Picture
    14 on at
    Re: Is there a possibility of having a local variable or anything close to a local variable?

    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?

  • cchannon Profile Picture
    4,702 Super User 2025 Season 1 on at
    Re: Is there a possibility of having a local variable or anything close to a local variable?

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 55 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 42 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 31 Super User 2025 Season 1

Overall leaderboard