cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Sort galley by calculated field in galley

I am displaying a galley which is based on one sharepoint list.  In my galley, I have a label where I am displaying the number of connected ID numbers in another sharepoint list using 

 

CountIf(StrikeRecords, StudentID=ThisItem.StudentID)

 

My question is there a way that I can sort my galley based on the value of this label in my gallery?  Currently I am sorting by name.

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@Anonymous 

My 1st suggestion is to use this code to count rows instead.  It will count up to 2000 matching records.  Your code will only look at the first 500 rows in the datasource and the count will be 500 or less.

 

CountRows(Filter(StrikeRecords, StudentID=ThisItem.StudentID))

 

My 2nd suggestion is instead of sorting by the label you should create a new collection and add the CountRows as a new column.  Replace my placeholder names with your datasource and column names.

 

ClearCollect(
    yourCollectionName,
    ForAll(
        your_datasource_name,
        {
            field1: field1,
field2: field2,
field3: field3, Count: CountRows(Filter(StrikeRecords, StudentID=ThisItem.StudentID)) } ) )

Then use this code in the Items property of your gallery.

 

Sort(yourCollectionName,Count,Descending)

 

---
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."

View solution in original post

3 REPLIES 3
mdevaney
Super User
Super User

@Anonymous 

My 1st suggestion is to use this code to count rows instead.  It will count up to 2000 matching records.  Your code will only look at the first 500 rows in the datasource and the count will be 500 or less.

 

CountRows(Filter(StrikeRecords, StudentID=ThisItem.StudentID))

 

My 2nd suggestion is instead of sorting by the label you should create a new collection and add the CountRows as a new column.  Replace my placeholder names with your datasource and column names.

 

ClearCollect(
    yourCollectionName,
    ForAll(
        your_datasource_name,
        {
            field1: field1,
field2: field2,
field3: field3, Count: CountRows(Filter(StrikeRecords, StudentID=ThisItem.StudentID)) } ) )

Then use this code in the Items property of your gallery.

 

Sort(yourCollectionName,Count,Descending)

 

---
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."

Anonymous
Not applicable

I did a workaround for this by first patching my sharepoint list and then adding the new field to my galley.  I like your solutions as well, but for my situation, i can use this number is other connected apps.

Hi Mdevaney,

 

Thanks for your suggestions, and I try to solve my problem the same as above. However, I try to use suggestion 2, but I can't get the ThisItem. I feel confused about where I should write the code. Could you help me? I look forward to your reply.

 

Best,

Qianting

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,994)