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 Automate / Avoiding variable use ...
Power Automate
Unanswered

Avoiding variable use in apply to each

(0) ShareShare
ReportReport
Posted on by 2

Greetings,

First help post but I have been using this board regularly for help.   Now I have a question without a obvious answer...

 

I have a flow with an apply to each.   I learned quickly when doing this it pays to avoid variables as you have to set concurrency to 1 if you do.   My specific issue is with using a switch inside an apply to each.  See the flow below, again all inside and apply to each.   I take job number which is say 20-6105 and grab "6" in Compose.   Switch takes that number and sets "Salesman" variable based on the Compose output.  The value in "Salesman" is used to point the Sharepoint Get Items to the correct list. 

 

The fourth position of job number, "6" in my example equates to the salesman.   I need a method to convert these AND use the correct answer to perform the get items.   I can't use compose as the "outputs()" will be different depending on the outcome of switch.  To be clear the flow below works perfectly.   Its simply WAY too slow.   The runtime is about 4 hours.   

 

So... Please help me get rid of this variable if possible.

 

flow.png

Categories:
  • v-litu-msft Profile Picture
    Microsoft Employee on at

    Hi @DaveHepler,

     

    Could you please share the run history that runtime is about 4 hours?

    I don't think set variable action will take too many times, generally, it just only takes serval seconds to run. And the 4 hours may be token by the Get items cause there are too many items.

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • DaveHepler Profile Picture
    2 on at

    Lin,

     

    I wasn't clear.   My flow runs as follows:

    1. get items from SharePoint list ~ 325 items.

    (Loop)

         2. For each item, read one or two CSV files with ~10 lines each.

         (Loop)     

               3. Add several items from these CSV to obtain totals held in several variables.

               4. Update SharePoint list item from 1. with totals.

    5. next item from 1. list.

     

    Please ignore "failure action"  this is simply checking for the second file that not all items have.  The flow does not fail and that is not taking the time.

     

    This results in nested loops.  Since I am setting variables inside loops, and variables are global,  I must set concurrency to 1, correct?   When I set concurrency to 1, runtime is increased by 20x.   I have similar flows where I was able to avoid variable use and instead use expressions and compose operations so I can keep concurrency high.   These other flows run quickly. ~ 15 minutes.

     

    1.png

     

    2.png

     

    3.png

     

    4.png

     

    5.png

     

    6.png

     

     

     

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

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 430

#2
11manish Profile Picture

11manish 341 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 282

Last 30 days Overall leaderboard