cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Collin_Davis
Advocate I
Advocate I

Numbered Items in a Gallery

Collin_Davis_0-1597264789301.png

As shown above, I have a gallery with a couple of entries in it. I am wanting be number each entry based off of which row it is in. If it is the first entry (in the first row), then I would like to have the number 1 displayed in a text box.

In the above screenshot, I had "This Item . Description" (with no spaces) as the main label, but wanted the number to be next to that. I created a second text box to try to test my desired action. I ended up trying an html text editor because it would allow the same look as a normal text box (unlike the rich text editor). With this, I tried the following code:

Concatenate("<ol><li>", This Item . Description)

This returned the correct look that I was wanting, but when I added a second entry to the gallery, the system did not auto-increment the number. Is there any way to accomplish this task?

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @Collin_Davis :

Could you tell me :

  • What is the gallery's items property?
  • How did you add the second entry?
  • What is your data source's primary key?(Unique identifier)I assume it is "ID".

The easiest way is to add an auto-incrementing field to your data source.

If you are unwilling to modify your data source, the only way is to use the data in the original data source to create a new collection .I've made a test for your reference:

1\Set the screen's OnVisible property to:

 

Clear(colNumberedInvoices); /*colNumberedInvoices is a custom collection*/
ForAll(yourdatasource, 
       Collect(colNumberedInvoices,
               Last(FirstN(AddColumns(yourdatasource,
                                "RowNumber",
                                CountRows(colNumberedInvoices)+1
                           ), 
                           CountRows(colNumberedInvoices)+1
                    )
               )    
       )
)

 

2\Add a label control into the gallery and set it's Text property to:

 

LookUp(colNumberedInvoicesm,ID=ThisItem.ID).RowNumber  /*I assume ID is the unique identifier of your data source*/

 

Because the Row Number is stored in colNumberedInvoicesm, we need to use lookup to find the corresponding record in colNumberedInvoicesm to get the value of rownumber.

The reason why I don't directly use colNumberedInvoicesm as the data source of the gallery is because the data structure of colNumberedInvoicesm and your data source is different, which may cause some errors.

Best Regards,

Bof

 

 

View solution in original post

3 REPLIES 3
mdevaney
Super User
Super User

@Collin_Davis 
You can use the code in this example to add a row number to a datasource or collection.  Then you could add the row number in a label within the gallery.

 

Link to Add A Row Number:
https://matthewdevaney.com/powerapps-collections-cookbook/add-a-row-number-column-to-a-collection/

 

 

If you'd like some further help, please supply any information I would need to recreate your problem.  I'd love to figure this out with you!

 

---
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-bofeng-msft
Community Support
Community Support

Hi @Collin_Davis :

Could you tell me :

  • What is the gallery's items property?
  • How did you add the second entry?
  • What is your data source's primary key?(Unique identifier)I assume it is "ID".

The easiest way is to add an auto-incrementing field to your data source.

If you are unwilling to modify your data source, the only way is to use the data in the original data source to create a new collection .I've made a test for your reference:

1\Set the screen's OnVisible property to:

 

Clear(colNumberedInvoices); /*colNumberedInvoices is a custom collection*/
ForAll(yourdatasource, 
       Collect(colNumberedInvoices,
               Last(FirstN(AddColumns(yourdatasource,
                                "RowNumber",
                                CountRows(colNumberedInvoices)+1
                           ), 
                           CountRows(colNumberedInvoices)+1
                    )
               )    
       )
)

 

2\Add a label control into the gallery and set it's Text property to:

 

LookUp(colNumberedInvoicesm,ID=ThisItem.ID).RowNumber  /*I assume ID is the unique identifier of your data source*/

 

Because the Row Number is stored in colNumberedInvoicesm, we need to use lookup to find the corresponding record in colNumberedInvoicesm to get the value of rownumber.

The reason why I don't directly use colNumberedInvoicesm as the data source of the gallery is because the data structure of colNumberedInvoicesm and your data source is different, which may cause some errors.

Best Regards,

Bof

 

 

pranavpatel
Regular Visitor

I found 1 article which shows to show sequence number without using collection here.

http://powerappslearning.com/serial-number-index-number-in-gallery-control-powerapps/.

 

I hope it will help you

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

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.

Users online (4,064)