cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
digiservice
Advocate II
Advocate II

Increment a value in a column within a ForAll loop

I am unsure how I would achieve this so hoping for some guidance.

 

I am uploading a local collection to a sharepoint list, that looks something like this:

ForAll(
    MyCollection,
      If(
           MyVariable = false And MyColumn = "New",
           Patch(
                 MySharePointList,
                 Defaults(MySharePointList),
                      {
                        Title: MyTitle,
                        Reference: Reference
                       }
                    )
        )
);

I want to append a number to the Reference column sequentially.

 

So if there are 3 items in the ForAll Loop the outputs would be:

Reference1
Reference2

Reference3 

 

And so on.

What is the best way to achieve this? I would prefer to do this in the upload as this is when we know categorically they final amount of rows that will be uploaded and therefore the sequential numbers that need applying?

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @digiservice ,

Based on the needs that you mentioned, I think a collection could achieve your needs.

 

Please consider take a try with the following formula:

Clear(Counter);
ForAll(
       MyCollection,
       If(
           MyVariable = false And MyColumn = "New",
           Collect(Counter, 1);   // Add formula here
           Patch(
                 MySharePointList,
                 Defaults(MySharePointList),
                      {
                        Title: MyTitle,
                        Reference: Reference & CountRows(Counter)    // Modify formula here
                       }
                    )
        )
);

 

please take a try with above solution, check if the issue is solved.

 

Best regards,

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

View solution in original post

6 REPLIES 6
Carsten_Growth
Power Apps
Power Apps

See this example

Clear(colNumberedInvoices);
ForAll(Invoices, 
       Collect(colNumberedInvoices,
               Last(FirstN(AddColumns(Invoices,
                                "RowNumber",
                                CountRows(colNumberedInvoices)+1
                           ), 
                           CountRows(colNumberedInvoices)+1
                    )
               )    
       )
)

@Carsten_Growth 
I recognize the code you supplied as a post from the blog of @timl.

Link to blog post: http://powerappsguide.com/blog/post/generating-row-numbers


It looks like @digiservice is conditionally patching information to the datasource based on status of a record.  Anyway to combine the code you supplied with what the original poster showed?

 

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

I'm just following along here to see what happens with this because I was building an answer last night - before I fell asleep lol. I've built a solution that works using @timl solution posted by @Carsten_Growth but I'd like to also see what others can produce as well to compare 🙂 

 

 

v-xida-msft
Community Support
Community Support

Hi @digiservice ,

Based on the needs that you mentioned, I think a collection could achieve your needs.

 

Please consider take a try with the following formula:

Clear(Counter);
ForAll(
       MyCollection,
       If(
           MyVariable = false And MyColumn = "New",
           Collect(Counter, 1);   // Add formula here
           Patch(
                 MySharePointList,
                 Defaults(MySharePointList),
                      {
                        Title: MyTitle,
                        Reference: Reference & CountRows(Counter)    // Modify formula here
                       }
                    )
        )
);

 

please take a try with above solution, check if the issue is solved.

 

Best regards,

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

View solution in original post

@v-xida-msft 

That's a really handy way to add a Counter into a ForAll() loop, I haven't seen that method before. Thanks for sharing!

This works perfectly thank you @v-xida-msft 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (75,656)