cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ajazz
Level: Powered On

Generating number to each row in collection

Hello awesome powerapps community!

I have tried different approaches to update an existing collection with a sequential number for each row of the collection.
Fx row 1 = 1
row 2 = 2,
row 3 = 3 etc.
But i can't get it work 😞


The collection i would like to update with a number sequence column is called "ReadyforExport"

Following syntax is one of my attempts:

ForAll (ReadyforExport, 
   Collect(ReadyforExport, 
     Last(FirstN(AddColumns(ReadyforExport, "RowNumber", CountRows(ReadyforExport)+1),
        CountRows(ReadyforExport)+1
         ) 
     )
   )
)



Are there a wonderful soul out there, who can help me solving this?

Have a great weekend

Best regards
Ajazz

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Generating number to each row in collection

Hi @ajazz 

If you collect the output into a new collection (for example, ReadyforExportNumbered), the formula should then hopefully work for you.

ForAll (ReadyforExport, 
   Collect(ReadyforExportNumbered, 
     Last(FirstN(AddColumns(ReadyforExport, "RowNumber", CountRows(ReadyforExportNumbered)+1),
        CountRows(ReadyforExportNumbered)+1
         ) 
     )
   )
)

Once you've generated the RowNumber column with the formula above, you could replace your ReadyforExport collection with your  ReadyforExportNumbered collection, if required.

ClearCollect(ReadyforExport,ReadyforExportNumbered) 

 

View solution in original post

5 REPLIES 5
Highlighted
Super User
Super User

Re: Generating number to each row in collection

@ajazz 

Take a look at this article written by forum member (and Flownaut) @timl You should be able to adapt the technique to your scenario.  http://powerappsguide.com/blog/post/generating-row-numbers

 

Tim's a pretty knowledgeable dude.  He even wrote one of the first books about PowerApps.

https://www.amazon.com/Tim-Leung/e/B0065L2JD4%3Fref=dbs_a_mng_rwt_scns_share

 

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

Super User
Super User

Re: Generating number to each row in collection

Thanks very much @mdevaney 🙂

@ajazz - if you're still stuck after reading that, post back here and I'm sure one of us can help. 

ajazz
Level: Powered On

Re: Generating number to each row in collection

Thanks @mdevaney & @timl,

I found that blog before posting, but somehow I can still not get it to work.

This is my syntax as a result of following his guide:

ForAll (ReadyforExport, 
   Collect(ReadyforExport, 
     Last(FirstN(AddColumns(ReadyforExport, "RowNumber", CountRows(ReadyforExport)+1),
        CountRows(ReadyforExport)+1
         ) 
     )
   )
)


Can you experts spot my errors?

Super User
Super User

Re: Generating number to each row in collection

Hi @ajazz 

If you collect the output into a new collection (for example, ReadyforExportNumbered), the formula should then hopefully work for you.

ForAll (ReadyforExport, 
   Collect(ReadyforExportNumbered, 
     Last(FirstN(AddColumns(ReadyforExport, "RowNumber", CountRows(ReadyforExportNumbered)+1),
        CountRows(ReadyforExportNumbered)+1
         ) 
     )
   )
)

Once you've generated the RowNumber column with the formula above, you could replace your ReadyforExport collection with your  ReadyforExportNumbered collection, if required.

ClearCollect(ReadyforExport,ReadyforExportNumbered) 

 

View solution in original post

Community Support Team
Community Support Team

Re: Generating number to each row in collection

Hi @ajazz ,

Could you please share a bit more about your scenario?

Do you want to add a Row Index column within your existing ReadyforExport collection?

 

Based on the formula you provided, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following formula (set the OnSelect property of a button to following) :

Clear(FinalCollection);
ForAll(
       ReadyforExport,
       Collect(
               FinalCollection,
               {
                 RowNumber: CountRows(FinalCollection) + 1,
                 Column1: ReadyforExport[@Column1],     // Specify same column names as that from your ReadyforExport collection within your FinalCollection
                 Column2: ReadyforExport[@Column2],
                 Column3: ReadyforExport[@Column3],
                 ...
               }
       )
)

Then you could use the FinalCollection as data source within your app instead of the original ReadyforExport collection.

 

Please consider take a try with above solution, then 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.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,074)