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 / ForAll Loop Issue (Cou...
Power Apps
Answered

ForAll Loop Issue (Counting each iteration)

(0) ShareShare
ReportReport
Posted on by 283

Background:

- Submit data is the collection where I store my data.
- Success Count is where I want to count each record that had an empty error table.   However, my code currently records ALL the items in SubmitData for each loop instead of just the count that went through without an error.  How can I filter it to only the item that is being evaluated in the ForAll loop? 

 

 

 

ForAll(
 SubmitData,
 If(
 IsEmpty(
 Errors('H2A Housing Inspection',
 (Patch('H2A Housing Inspection'
 ,Defaults('H2A Housing Inspection'),
 {Title: "",
 DDate: Now()}
 )
 )
 )
 ), 
 Collect(SuccessCount,SubmitData.Counter)
 )
 );
Notify(
 CountA(SuccessCount.Counter) & " out of " & 
 CountA(SubmitData.region5),NotificationType.Success)

 

 

Categories:
  • Verified answer
    mdevaney Profile Picture
    29,993 Moderator on at

    @dyee4614 

    My approach to the solution is different from yours since it increments a Value stored in a 1 row collection each time there is a success and it does not rely on filters.  Please study the changes I made carefully and let me know if you have any questions.

     

    // reset success counter to 0
    ClearCollect(colSuccessCount,{Value: 0})
    
    ForAll(
     SubmitData,
     If(
     IsEmpty(
     Errors('H2A Housing Inspection',
     (
     Patch(
     'H2A Housing Inspection',
     Defaults('H2A Housing Inspection'),
     {Title: "", DDate: Now()}
     )
    
     )
     )
     ),
    
     // increment success counter if there are no error
     Patch(colSuccessCount,{Value: First(colSuccessCount).Value + 1})
     )
    );
    
    Notify(
     // display the counter result
     First(colSuccessCount).Value & " out of " & 
     CountA(SubmitData.region5),NotificationType.Success
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Verified answer
    v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @dyee4614 ,

     

    Please modify your codes as below:

     

    ForAll(
     SubmitData,
     If(
     IsEmpty(
     Errors('H2A Housing Inspection',
     (Patch('H2A Housing Inspection'
     ,Defaults('H2A Housing Inspection'),
     {Title: "",
     DDate: Now()}
     )
     )
     )
     ), 
     Collect(SuccessCount,Counter)
     )
     );
    Notify(
     CountA(SuccessCount.Value) & " out of " & 
     CountA(SubmitData.region5),NotificationType.Success)

     

    I modify 'SubmitData.Counter' to Counter, because 'SubmitData.Counter' returns a single-line table, so every time it loops, the whole single-line table is stored into the SuccessCount collection.

    If you change to use Counter, each time it loops, it will only return the counter value of the currently traversed record without error, and collect to SuccessCount collection.

    Meanwhile, you need to modify 'SuccessCount.Counter' to 'SuccessCount.Value', because the column name is changed.

    Sik

  • dyee4614 Profile Picture
    283 on at

    It worked!  Thanks for your help.

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 Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard