cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Srinath
Helper III
Helper III

Row numbers in Power Apps gallery

Hi Guys,

I have a gallery where i have to display a set of qns from a sharepoint lists for a quizing app. The user can choose the topic before the quiz starts. I have a set of qns storedin a SharePoint list. The qns in the gallery will be filtered according to the topic selected in the previous screen.

 

I want a row number label to be added in the gallery so that user can see the question numbers. I have added a new column to the collection where all my qns are stored which has the row number, but what happens is that if the user selects topic 2, then the question number starts from 6 if there are 5 qns in topic 1. I want the question numbers to start from one irrespective of the topic the user chooses.

 

I have written the below code in the OnStart property of the app.

 

Clear(CollQn);
ForAll(QuestionsList,
Collect(CollQn,
Last(FirstN(AddColumns(QuestionsList,
"RowNumber",
CountRows(CollQn)+1
),
CountRows(CollQn)+1
)
)
)
);

 

Kindly let me know how I can solve my issue with this numbering. Any help will be greatly appreciated.

 

Regards

Sri

1 ACCEPTED SOLUTION

Accepted Solutions
RusselThomas
Microsoft
Microsoft

Hi @Srinath ,

It sounds like you're looking for an independent collection index.

I usually do this by first creating the index column and populating it with a placeholder, then updating it - this ensures you're indexing current records and not adding empty ones for the index.    

To demonstrate we'll just create a new collection, but if 'QuestionsList' is your collection you can just do the AddColumns there when you initially collect it;

ClearCollect(collectIndexedQuestions, AddColumns(QuestionsList, "RowNumber", 0));
UpdateIf(collectIndexedQuestions, RowNumber=0, {
   RowNumber: Last(SortByColumns(collectIndexedQuestions, "RowNumber", Ascending)).RowNumber + 1
  })

Hope this helps,

RT

View solution in original post

4 REPLIES 4
RusselThomas
Microsoft
Microsoft

Hi @Srinath ,

It sounds like you're looking for an independent collection index.

I usually do this by first creating the index column and populating it with a placeholder, then updating it - this ensures you're indexing current records and not adding empty ones for the index.    

To demonstrate we'll just create a new collection, but if 'QuestionsList' is your collection you can just do the AddColumns there when you initially collect it;

ClearCollect(collectIndexedQuestions, AddColumns(QuestionsList, "RowNumber", 0));
UpdateIf(collectIndexedQuestions, RowNumber=0, {
   RowNumber: Last(SortByColumns(collectIndexedQuestions, "RowNumber", Ascending)).RowNumber + 1
  })

Hope this helps,

RT

View solution in original post

Eelman
Super User
Super User

@Srinath 

You need to run that code after the user has made their selection. Running it at App OnStart adds a Row Number to your full list, which is why Topic 2 starts at 6 and not 1.

Hi @RusselThomas ,

 

Thank you so much. I have tried your solution and it works well.

 

I'm accepting it as the solution for my issue.

 

Regards

Sri

 

 

Hi @Eelman ,

 

I have gone with the solution suggested by @RusselThomas . I guess your suggestion will also work fine.

 

Thanks again for reaching out.

 

Regards

Sri

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,060)