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 / Issues with multiple s...
Power Apps
Answered

Issues with multiple sort options on gallery

(0) ShareShare
ReportReport
Posted on by 782

I have a gallery which consists of items from a SP list.

I have two columns in a gallery. One is named Facility. The other is the SP column for last modified.
I have a textbox used for searching the gallery.

 

I'm trying to apply ascending/descending sorting to both columns in the gallery. 

 

When doing this for one column, I can do so without issue. When doing it for both, it seems to break.

 

The really weird part is this works in the designer but when I publish the app it does not. 

 

Screen OnVisible: 

 

Concurrent(ClearCollect(collAllSiteVisitDetails, SiteVisitDetails), ClearCollect(collAllSVTDetails, SVTList)); 
Set(FacilitySort, false); 
Set(LastSort, "fac");
Set(LastUpdated, true)

 

Button for Facility Sorting OnSelect: 

 

UpdateContext({FacilitySort: !FacilitySort}); 
UpdateContext({LastSort: "fac"})

 

 

Button for Last Modified Sorting OnSelect:

 

UpdateContext({LastUpdated: !LastUpdated});
UpdateContext({LastSort:"mod"})

 

 

Gallery Items:

If(LastSort="fac", SortByColumns(Search(SiteTracker, textSearch.Text, "Title"), "Title", If(FacilitySort, Descending, Ascending)), SortByColumns(Search(SiteTracker, textSearch.Text, "Title"), "Modified", If(LastUpdated, Descending, Ascending)))

 

Categories:
I have the same question (0)
  • Mr-Dang-MSFT Profile Picture
    Microsoft Employee on at

    Hi @notj ,

    I've formatted your formula for better understanding:

    If(
     LastSort="fac", 
    
     SortByColumns(
     Search(SiteTracker, textSearch.Text, "Title"), 
     "Title", If(FacilitySort, Descending, Ascending)
     ), 
     
     SortByColumns(
     Search(SiteTracker, textSearch.Text, "Title"), 
     "Modified", If(LastUpdated, Descending, Ascending)
     )
    )

     

    It looks like you are using two variables to affect the sort:

    • LastSort affects whether you're sorting by Title or Modified columns
    • LastUpdated affects whether the sort is descending or ascending. 

    Problem: your app works when designing in studio, but not when running the app.

     

    Can you run the app and grab a session id number when you see this behavior?

    http://aka.ms/pa/sessionid

  • notj Profile Picture
    782 on at

    @Mr-Dang-MSFT 

    Session ID: 392917d8-ad06-45b0-a09d-9d5aeeea0cf4
    PowerApps 3.19111.33

     

    Edit: Well, it's no longer working in Studio now. I'm not sure why.

  • notj Profile Picture
    782 on at

    I'm not really sure what's going on with it. Yes, I'm sorting by two variables, but one is just telling the gallery which of the other to sort by. If that makes sense.

  • Mr-Dang-MSFT Profile Picture
    Microsoft Employee on at

    @notj ,

    SharePoint is non-delegable with the Search() function. This means the filtering you are expecting may not return the full results you're expecting if it is outside the first 500 (or 2000) records.

     

    Doc: https://docs.microsoft.com/powerapps/maker/canvas-apps/delegation-overview

     

    If you would like to use the textSearch box with a SharePoint list, you can use StartsWith(). It is not equivalent to Search() but can search text strings at their start.

    Filter(SiteTracker, StartsWith(Title, textSearch.Text))

     

    That said, the first best experience is to use the strengths of SharePoint itself for filtering and viewing records and bring in Power Apps when you need to take actions with other connectors.

  • notj Profile Picture
    782 on at

    @Mr-Dang-MSFT what? I don't have a problem with the search. It's working fine. Are you saying using the search is preventing me from being able to sort by two different fields depending on what you picked?

  • notj Profile Picture
    782 on at

    @Mr-Dang-MSFT I tried without the search, same problem. 

    If(LastSort="fac", SortByColumns(SiteTracker, "Title", If(FacilitySort, Descending, Ascending)), SortByColumns(SiteTracker,"Modified", If(LastUpdated, Descending, Ascending)))
  • notj Profile Picture
    782 on at

    And now it's back to working in the editor but not when published. Any explanation why something will work fine in the editor but when you publish the app it's broken?

    So I've narrowed down the problem to be the buttons that change the sort. They don't seem to be doing what they should. 

    Here's an alternate to the code to one of the buttons. This still ONLY works in the editor.

    UpdateContext({LastSort:"mod"});
    If(LastUpdated=true, UpdateContext({LastUpdated: false}), UpdateContext({LastUpdated: true}))


     I have some labels on the screen set to display the values of these variables. They update fine when using the preview feature in the editor. When I publish  the app and run it like normal, the only variable that changes is the LastSort.

    I also want to clarify that replacing the If with UpdateContext({LastUpdated: !LastUpdated}) also works fine in the editor but the same result when published. 

  • notj Profile Picture
    782 on at

    Honestly, it doesn't even work with one sort. Neither of the below lines will function correctly when published. They will change the value once, but then never again.

     

    If(LastUpdated=true, UpdateContext({LastUpdated: false}), UpdateContext({LastUpdated: true}))
    
    
    UpdateContext({LastUpdated:!LastUpdated})

     

     

  • Mr-Dang-MSFT Profile Picture
    Microsoft Employee on at

    @notj,

    Can you tell me which App settings you have enabled? Go to File > Settings > Advanced Settings:

    image.png

  • notj Profile Picture
    782 on at

    @Mr-Dang-MSFT 

     

    Delayed Load - On

    Use non-blocking OnStart rule - On

    Explicit column selection - Off

    Relation data, etc. - On

    More reliable Concurrent - On

    Improve data source experience - On

    Common Data Service new file - Off

    Enable improve data table - On

    Enable enhanced Microsoft SQL - Off

     

    Experimental

    All Off

     

    Deprecated 

    Enable rules - Off

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard