cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
michalparal222
Regular Visitor

Fastest way to handle apply to each

Hi Power community,

I have question regarding the fastest way how to proceed with following scenario.

I have 5 SharePoint lists, one of them contains basic information about employees, and the rest some additional information - related records, lookup columns etc.. There is about 650 employees and I need to gather records valid for them, that means 650 times to go thru apply to each loop.

The actions inside apply to each: 

michalparal222_0-1714027247456.png

So as you can see only data operations, no API calling (like creating records in SharePoint etc..) 
When I run this flow with only 100 employees (records in SharePoint list) it takes about 20 seconds, but when I try to run it for all 650 records, it takes 5-10 hours, I mean that is crazy 😄 

What should the best approach? Divide the actions into separate parallel loops? Use concurrency inside the loop?
I have tried some of mentioned approaches, like parallel loops, concurrency, combinations of those two, but it still takes hours, I would like to do it in minutes. 
Thank you for your advices 🙂 

1 ACCEPTED SOLUTION

Accepted Solutions
Chriddle
Super User
Super User

I think a database would be much more convenient for managing all of these relationships than Sharepoint lists.

What about building a Powerapp?

 

However, if you want to stick with Power Automate and SP lists, I recommend doing all of these filters and queries using xpath.

 

I created a simplified version of this. You can find the JSON in the attachment.

Take a look and decide if you want to go down this thorny path.

View solution in original post

11 REPLIES 11
leo85
Continued Contributor
Continued Contributor

Hi @michalparal222,

I see two potential optimizations.

First, put all the select statements into one statement. 

Second, activate concurrency under settings of the action. This will open multiple threads, so that multiple records are worked on in parallel. With 650 employees, setting it to 20 should be a good option.

Regards

 

------------------------------

If my answer solved your issue, please mark it as a solution.

If what I wrote helped you, please give it a thumbs up.

 

Hi @leo85 ,

 

I have tried concurrency with 10-50 set, but as I mentioned with 100 records it took appr 20 seconds, but with 650 records it takes hours.
The Select actions are from different filter array actions, so those cannot be combined. The Last compose action is using union to combine the outputs from the Selects. 

leo85
Continued Contributor
Continued Contributor

With the concurrency set to 50 you will lose quite some time to the setup of all of the threats. Try to fine tune the number of concurrencies.

You may be running into connector limitations, if your concurrency number is high. With 650 records it also depends on your license if you run into API call limitations.

 

Most likely there are some loops which fail and drag up the time.  You could use process advisor to analyse the flow. It'll give you information on which actions take a lot of time.

Chriddle
Super User
Super User

I'm wondering if you can do this without even using an Apply to each at all.

If you show more details and example JSONS, I could take a look.

I know I should not use the concurrency set to 50. When I wrote a tried 10-50 a meant a I've tried 10,15,20,25, etc.. almost every time with same result. Check this:

650 records, concurrency to set to 20, 3,5 hour

michalparal222_0-1714043067350.png

100 records, concurrency set to 20, 14 seconds:

michalparal222_1-1714043171521.png

 

with concurrency off, I stopped it after 10,5 hours

michalparal222_2-1714043607747.png

 

 

 

As you can see no loop have failed. Every actions inside every loop shows duration 0s, sometimes 1s. These data operations do not use any connector, at least I think so. Of course something is processing these data on background, but I have not found any limits about that. 

leo85
Continued Contributor
Continued Contributor

Even if they don't fail, there may be issues that take some in one of the loops.

Instead of having one loop with 650 items, you can try to have 6 or 7 parallel loops with only around 100 items. To do this, you can sort the result from the SharePoint action by a specific column and then filter it, to have around 100 items each. 

Well @Chriddle of course I would love that, but I did not found such way. It is a pretty complex solution it may take you a while before you will crack it 🙂 

 

Lists:

  1. Employees
    1. Every employee have some position
  2. Obligation
    1. Only list with Obligation names, used for lookups in other lists
  3. Obligation & Position
    1. Generates Obligation for employee to a Obligation maintenance list
    2. Auto generated based on employee position
  4. Obligation maintenance
    1. All generated obligations. 1 row = Obligation assigned to an employee
    2. Every employee can have multiple obligation (from 5 to 20) means from 5 to 20 rows
  5. Tasks
    1. Only list task names, used for lookups in other lists
  6. Obligation & task
    1. One task can have multiple obligations
  7. Task assignment
    1. Assign a task to an employee, one row means employee with task 
      1. This auto generates the obligations to the Obligation maintenance list
      2. Once again one task can have multiple obligations, so this assignment can generate 5 obligations easily. 

And my flow output needs to be what an employee should have, means the exact names of the obligations. So it needs to go thru all these list and:
Based on the employee position get the list of obligations
If the employee have some task assigned, then get the names of the obligations tied to this task
Then union those two obligation array into one.

There is X other flows that are maintaining the whole solution, X other lists that I did not mentioned. I have attached an excel which could help you understood it. 

 

Chriddle
Super User
Super User

I think a database would be much more convenient for managing all of these relationships than Sharepoint lists.

What about building a Powerapp?

 

However, if you want to stick with Power Automate and SP lists, I recommend doing all of these filters and queries using xpath.

 

I created a simplified version of this. You can find the JSON in the attachment.

Take a look and decide if you want to go down this thorny path.

Wow @Chriddle, thank you! I have learned some new skills. Thank you for your idea and sharing the json. 

I have followed your example and created pretty much the same from scratch, but with more steps so I could understand it. I have one or two more questions for you.

My ultimate goal it to compare two things

Already existing obligations (items present in SharePoint list Employee Obligations maintenance) - I have this in action "Compose-FinalObligations"

with

Obligations that should be there (output of the actions you helped me to create (task obligations & position obligations) - I have this in action "Compose-FinalExistingObligations"

 

See my JSON attachment. 

 

So my question is:

Now I have these two outputs what would be the best way to compare those? Specifically, if Already existing obligations for employee are the same as Obligations that should be there for employee, if not the result should be the difference.

 

And second question:

Action "Select-ExistingObligations" takes about 45 minutes (it is about 4000 records) I can live with that, but would there be even faster way? 


BTW: I know using dataverse and power apps with relate functions would be much more better, but in this case it is from multiple reasons just not possible. 

Chriddle
Super User
Super User

Looks like the file is empty

michalparal
Frequent Visitor

Sorry, I've attached the updated one. 

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (4,444)