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 / If(SortDescending1, As...
Power Apps
Answered

If(SortDescending1, Ascending, Descending) does not work for "SortByColumns" function

(0) ShareShare
ReportReport
Posted on by 233

I've created a new screen and gallery in my app and am trying to sort the data shown in the gallery in ascending order. I've used "SortByColumns" extensively in my app and don't have trouble in any other form. But on this new form it looks like "If(SortDescending1, Ascending, Descending) " is not acceptable to the "SortByColumns" function.

 

This is what I'm trying to use:

 

If(ComboBox2.SearchText = "",
                       TruckStockInventoryDB,
                       SortByColumns(Filter(TruckStockInventoryDB, Title = First(ComboBox2.SelectedItems).Title Or Title =                                                 ComboBoxSearchText.Text), "Title", If(SortDescending1, Ascending, Descending)))

SortByColumns.png

 

I've tried using just "Ascending", and while that does not produce an error it does not actually sort my gallery.

 

What am I missing?



Categories:
I have the same question (0)
  • awalker Profile Picture
    233 on at

    I found that I missed the sort button on the ribbon at the top of the screen that established the SortDescending1 variable.

    I added the sort button and variable but and the error went away. However, the gallery is still not sorting.

     

    SortByColumns 2.png

     

    SortByColumns 3.png

    I am not sure why the gallery won't sort at this point.

  • WarrenBelz Profile Picture
    156,409 Most Valuable Professional on at

    @awalker ,

    If you put on the icon

    UpdateContext({SortDescending1:!SortDescending1})

    it will sort by your Title field - is this the field you want to sort on?
    However looking further, it will only sort with something in your search box - try this

    SortByColumns(
     Filter(
     TruckStockInventoryDB, 
     Len(ComboBox2.Selected.Title)=0 || Title = ComboBox2.Selected.Title 
     ),
     "Title",
     If(
     SortDescending1, 
     Ascending, 
     Descending
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • awalker Profile Picture
    233 on at

    Thank you for responding. Here is what I get when replacing my code with the one provided:

     

    SortByColumns 4.png

     

  • WarrenBelz Profile Picture
    156,409 Most Valuable Professional on at

    @awalker ,

    Bracket in the wrong place - dangers of free-typing code - try it now.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • awalker Profile Picture
    233 on at

    Oops. Ok, I tried it again:

     

    SortByColumns 5.png

     

    The code has no error, but the gallery still only sorts in descending order.

     

    Greetings

  • awalker Profile Picture
    233 on at

    I should note that when I push the sort button UpdateContext({SortDescending1: !SortDescending1}), the list in Sharepoint sorts accordingly, but the gallery does not.

  • WarrenBelz Profile Picture
    156,409 Most Valuable Professional on at

    @awalker ,

    What do you mean the list does and the gallery does not? I assumed the code is on the Items of the Gallery?

  • awalker Profile Picture
    233 on at

    The code is on Items of the gallery. For some reason the sharepoint list will sort ascending and descending when I click the reorder button. But the gallery will stay the same. 

  • awalker Profile Picture
    233 on at

    Well, I promise it was resorting my sharepoint list earlier, but now I cannot repeat it. Neither the Sharepoint lists or gallery is resorting at this point.

  • WarrenBelz Profile Picture
    156,409 Most Valuable Professional on at

    @awalker ,

    There is absolutely nothing wrong with that code and it should sort - I assume you have the field Title displayed in your gallery (label with ThisItem.Title) and that is what you are expecting to sort on?

    Also put a Label on the screen with the Text SortDescending1 and see if it changes from false to true and back again when you push the button.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 207 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 150 Super User 2026 Season 2

Last 30 days Overall leaderboard