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 / Gallery - Sort and If ...
Power Apps
Answered

Gallery - Sort and If Statement

(2) ShareShare
ReportReport
Posted on by 91
Hello, 
 
I'm still new to Power Apps and have been doing a lot of research to get me by. I'm stumped now, I'm currently using:
 
"If(Lookup.Text<>"",(Search(Routes,Lookup.Text,Title)),Routes)"
 
In the Items field and it works correctly. But I need to change the Sort of the that Ascending departure times. I've looked at Set and Sort/SortByColumns and they are not working well together. 
 
TIA!
Categories:
I have the same question (0)
  • Suggested answer
    KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at
    Hey. If you replace this:
    (Search(Routes,Lookup.Text,Title)),Routes)
     
    With this, and change the Power Fx to match your columns, etc:
    SortByColumns(
      Search(Routes,Lookup.Text,Title),Routes,
      "departuretime",
      SortOrder.Ascending
    )
     
    Does sorting work as expected?
  • zw2348 Profile Picture
    91 on at
    Keith, 
     
    Thanks for the response! I changed the formula to match my data source/items. 
     
     
    If(RouteLookup.Text<>"",SortByColumns(Search(OutboundRoutes,RouteLookup.Text,Title)),OutboundRoutes,"Departure Time",SortOrder.Ascending)
     
    PA is giving me 3 issues
     
    Unexpected Characters. The Formula contains 'Eof' where 'ParenClose' is expected. 
    This error occurs if, for example, a formula contains '{Val@ 7}' instead of '{Val: 7}'. When you set a variable the syntax requires a colon instead of an "at" symbol.
     
    Invalid argument type (Table). Expecting a Text Value instead.
     
    The function 'SortByColumns' has some invalid arguments.
  • Suggested answer
    KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at
    Thanks for the follow-up. I think we're close! What happens if you use this Power Fx code snippet?:
    If(RouteLookup.Text<>"",
      SortByColumns(
        Search(OutboundRoutes,RouteLookup.Text,Title),
        "Departure Time",
        SortOrder.Ascending
    )
     
  • zw2348 Profile Picture
    91 on at
    Very close! Only returned error is the Unexpected Error
     
    Unexpected Characters. The Formula contains 'Eof' where 'ParenClose' is expected. 
    This error occurs if, for example, a formula contains '{Val@ 7}' instead of '{Val: 7}'. When you set a variable the syntax requires a colon instead of an "at" symbol.
     
    The RouteLookup is a reference to the new Text (Preview) box. 
     
  • Suggested answer
    KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at
    Ooh, almost there! I think I missed a bracket - does this work?
    If(RouteLookup.Text<>"",
      SortByColumns(
        Search(OutboundRoutes,RouteLookup.Text,Title),
        "Departure Time",
        SortOrder.Ascending
      )
    )
     
  • zw2348 Profile Picture
    91 on at
    99% there.. now I don't understand why, when the text box is empty the gallery is empty as well. But it is sorted correctly. That part of the formula really didn't change.. 
     
     
  • Verified answer
    KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at
    I think that's happening because of the first check in the If statement - if you change to this, is the behaviour different?:
    SortByColumns(
      Search(OutboundRoutes,RouteLookup.Text,Title),
      "Departure Time",
      SortOrder.Ascending
    )
    If any of my posts work, please mark them as the answer 😊
  • zw2348 Profile Picture
    91 on at
    That's it! Thank you!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 430

#2
timl Profile Picture

timl 318 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard