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

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Count errors on "Apply...
Power Automate
Unanswered

Count errors on "Apply to Each"

(0) ShareShare
ReportReport
Posted on by

Hi,

 

I have an Apply to Each loop that might fail for some values because it tries to find those values in some table that, in some cases, don't exist. Is it possible to get the number of times the Apply to Each fails and add that number into a variable?

 

Thanks

 

Ezequiel

Categories:
I have the same question (0)
  • Verified answer
    eliotcole Profile Picture
    4,363 Moderator on at
    Re: Count errors on "Apply to Each"

    Yeah! I use error handling frequently, @ezequiel !

     

    1. Create an integer variable before your loops are running (I'd call it errorCountVAR).
    2. Then after whatever action within the loop fails create two branches one for success, and one for errors.
      • In the success branch put the next action that you already had.
      • In your error branch put an Increment variable action and increment your variable.
    3. In your very first failure branch action;
      1. click the menu dots, and select 'Configure run after',
      2. now untick 'is successful', 
      3. finally tick 'has failed'.
    4. Now the next action must bridge the branches, so I usually create a standalone Compose action and name it something pointless (like "Continuance") with nonsense inside.
      1. Click the menu dots on the Compose, and select 'Configure run after'
      2. Now make sure that all of the tick boxes are checked and click 'Done'.
      3. Now do the same again, except this time click on the action below to check its boxes.

    error handling.jpg

     

    error handling - run after.jpg

     

     

     

     

    Now your flow can continue as normal, and you can use errorCountVAR anywhere after the Apply to each loop.

     

    We can enhance this with array variable and more, but essentially this will count the total number of errors

     

    Advanced - Via Array

    If you wanted to check back to which values had errored, I've made an assumption and stored the value name in valueVAR earlier on here:

    error handling - deeper.jpg

    error handling - deeper - run after.jpg

     

     

    Now you can call upon this errArrVAR array and have a list of values that failed. In this particular instance the error count is redundant, as you can do a length() function in an expression to count the values that failed.

     

     

    Even More Advanced

    However, you could also have multiple places where errors could be counted within a different loop for a given value. Here you would just:

    1. Add a Condition action at the end of the loop;
      1. Yes branch will only run if errorCountVAR is greater than 0.
      2. No branch is empty
    2. Move the errArrVAR JSON compose action in to the Yes branch, then in the text of errArrVAR JSON;
      1. add a comma after the last quote,
      2. add a new line with   "valueErrCount": errorCountVAR (where the errorCountVAR part is the variable)
    3. Move the Append to errArrVAR after the errArrVAR JSON compose action in the Yes branch.
    4. Finally, still in that Yes branch, set the errorCountVAR one last time back to zero for the next loop.

    multi balti.jpg

     

    Now if you run the flow ... if you call the array in an action after the Apply to each loop, you'll have something like:

    [
     {
     "valueErrored": "value2",
     "valueErrCount": 4
     },
     {
     "valueErrored": "value8",
     "valueErrCount": 1
     },
     {
     "valueErrored": "value21",
     "valueErrCount": 6
     }
    ]

    With that you can identify which value had how many errors. I often use this for loops that have 2 or 3 HTTP calls to capture failures in the call. 🙂

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard