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 Apps
Answered

Sort Gallery issue

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a gallery with the following formula in the Items property

Switch(
 locSortColumn,
 "Title", Sort('MMRS Trailer', Title, If(locSortAscending, Ascending, Descending)),
 "Location", Sort('MMRS Trailer', Location, If(locSortAscending, Ascending, Descending)),
 'MMRS Trailer'
)

I have a Gallery, two buttons and a search bar.

 

Issue 1: How do I add my search terms in the above code? I've tried using "|", "&", "And" 

Can't figure out that syntax

 

Issue 2: When I click sort by location, it works but my column has text and numbers in it. (Box 1, Box 2, Left Rear, etc) 

So it is displayed as: Box 1, Box 10, Box 11, Box 2 and so on. 

 

Anyone have a cool trick to fix this issue?

Thanks

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Please consider changing your Formula to the following:

    SortByColumns(
     'MMRS Trailer', 
     Coalesce("Title", locSortColumn),
     If(locSortAscending, Ascending, Descending)
    )

     

    It is not a good practice to use a Switch statement in the Items property as this can lead to issues with the resulting schema of the records.

    The above formula performs what you are looking for.  If locSortColumn is blank (i.e. has not been chosen yet), then the formula will default to sort on the Title...you can change that as needed.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I tried your suggestion, had to revert to my prev code. That code made my buttons loose functionality.

    Thanks for the assistance, my issue is the same though. 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Apologies...I had a typo in the formula.  It should have been:

    SortByColumns(
     'MMRS Trailer', 
     Coalesce(locSortColumn, "Title"),
     If(locSortAscending, Ascending, Descending)
    )

    Had the Coalesce backwards.

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I figured it out.

    I had to add a Number column though. But this is my end result

    SortByColumns(
     Search('MMRS Trailer', TextSearchBox2.Text, "Title", "Location"), 
     Coalesce(locSortColumn, "Title"),
     If(locSortAscending, Ascending, Descending)
    )

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 326 Most Valuable Professional

#2
11manish Profile Picture

11manish 168

#3
sannavajjala87 Profile Picture

sannavajjala87 75 Super User 2026 Season 1

Last 30 days Overall leaderboard