web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : AVdfkzoGi6CpMUnI6WVeJV
Power Apps - Building Power Apps
Unanswered

Assign sequence number to each gallery item row within a category, then start the sequence over with the next category. Display result as text label in the gallery item.

Like (0) ShareShare
ReportReport
Posted on 17 Oct 2023 10:53:37 by 5

I have a gallery in Power Apps which pulls data from various Dataverse tables and displays it as text labels within my gallery. The primary category column contains duplicates, but each subcategory can only appear once per primary category.

 

I wish to assign a number sequence and display it in a text label within each gallery item. The sequence should start counting from 1 and add 1 for each row (i.e. each subcategory) with the same primary category, then start over again from 1 once the primary category changes, and so on.

 

In the attached picture you can see a very simplified illustration of what I am trying to do. The "sequence" column values are what I want to assign and display within each gallery item row. I have been trying for quite some time to figure out a way to do this, but so far I have not been successful. Any advice?

 

  • uwenagel Profile Picture
    382 on 19 Oct 2023 at 12:52:12
    Re: Assign sequence number to each gallery item row within a category, then start the sequence over with the next category. Display result as text label in the gallery item.

    You have to replace _yourSource with the name of your source table. "PrimeCat" and "SubCat" should be replaced by the column names in your table.

     

    Please click 'Accept as solution' if my post helped you solve your issue. This will help others find it more readily. It also closes the item.

  • oyvind Profile Picture
    5 on 19 Oct 2023 at 12:16:26
    Re: Assign sequence number to each gallery item row within a category, then start the sequence over with the next category. Display result as text label in the gallery item.

    @uwenagel I really appreciate you taking the time to try to help me out.

    Unfortunately I am having some trouble adapting your code, but I'm sure the problem is more with my lack of experience and the complexity of my actual dataset than it is with your code.

    Do I need to replace everything that starts with an underscore (i.e. _data, _yoursource, and _items)? If so, what's the difference between each of them? Should "PrimeCat" and "SubCat" be replaced by my actual column names, or are they only for use within the collection?

  • uwenagel Profile Picture
    382 on 18 Oct 2023 at 07:31:07
    Re: Assign sequence number to each gallery item row within a category, then start the sequence over with the next category. Display result as text label in the gallery item.

    Hi @oyvind

    It took me a while to create the code. But now I think I can provide an answer:

     

    ClearCollect(
     colTemp,
     With(
     {
     _data: ForAll(
     GroupBy(
     _yourSource,
     "PrimeCat",
     "_items"
     ),
     {
     PrimeCat: PrimeCat,
     Rows: ForAll(
     Sequence(CountRows(_items)),
     Patch(
     Index(
     _items,
     Value
     ),
     {RowN: Value}
     )
     )
     }
     )
     },
     ForAll(
     Sequence(CountRows(_data)),
     Patch(
     Index(
     _data,
     Value
     ),
     {RowX: Value}
     )
     )
     )
    );
    ClearCollect(
     colList,
     ShowColumns(
     RenameColumns(
     Ungroup(
     colTemp;
     "Rows"
     ),
     "RowN",
     "Sequence"
     ),
     "PrimeCat",
     "SubCat",
     "Sequence"
     )
    )

     

    The collection colList in the end contains the resulting table.

     

    I hope you can adapt the code according to the actual names of your sourcetable and your column names.

     

    Please click 'Accept as solution' if my post helped you solve your issue. This will help others find it more readily. It also closes the item.

  • oyvind Profile Picture
    5 on 17 Oct 2023 at 12:17:23
    Re: Assign sequence number to each gallery item row within a category, then start the sequence over with the next category. Display result as text label in the gallery item.

    Thanks, @ANB. That helps me to assign row numbers for the entire table in my gallery, however I need the count to start over every time there is a row with a different category label than its preceding row.

  • ANB Profile Picture
    7,128 Super User 2025 Season 2 on 17 Oct 2023 at 11:02:50
    Re: Assign sequence number to each gallery item row within a category, then start the sequence over with the next category. Display result as text label in the gallery item.

    Hi @oyvind , This can help you:

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Numbered-Items-in-a-Gallery/m-p/658074#M209592

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

     

    -----------------------------------------------------------------------------------------------------------------------------

    I hope this helps.

    Please click Accept as solution ✅ if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs up.👍

    Thanks,
    ANB


     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2