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 Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (4,621)