cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dyee4614
Helper V
Helper V

ForAll Loop Issue (Counting each iteration)

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)

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
mdevaney
Super User
Super User

@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."

View solution in original post

v-siky-msft
Community Support
Community Support

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

View solution in original post

3 REPLIES 3
mdevaney
Super User
Super User

@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."

v-siky-msft
Community Support
Community Support

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
Helper V
Helper V

It worked!  Thanks for your help.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,020)