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?
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.
@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?
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.
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.
Hi @oyvind , This can help you:
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
WarrenBelz
791
Most Valuable Professional
MS.Ragavendar
410
Super User 2025 Season 2
mmbr1606
275
Super User 2025 Season 2