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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Assign sequence number...
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.

(0) ShareShare
ReportReport
Posted on 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?

 

Skjermbilde 2023-10-17 124627.png
Categories:
I have the same question (0)
  • ANB Profile Picture
    7,250 Super User 2026 Season 1 on at

    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


     

  • oyvind Profile Picture
    5 on at

    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.

  • uwenagel Profile Picture
    382 on at

    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 at

    @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 at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 536

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Haque Profile Picture

Haque 305

Last 30 days Overall leaderboard