cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper III
Helper III

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

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?



1 ACCEPTED SOLUTION

Accepted Solutions

@awalker ,

That was the problem in your original code as you had the search box text outside your Sort, but the code I gave you put it inside - just for a debugging exercise, try this

Sort(
   If(
      Len(ComboBox2.Selected.Title)=0, 
      TruckStockInventoryDB, 
      Filter(
         TruckStockInventoryDB
         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.

View solution in original post

14 REPLIES 14
Helper III
Helper III

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.

@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.

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

 

SortByColumns 4.png

 

@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.

Oops. Ok, I tried it again:

 

SortByColumns 5.png

 

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

 

Greetings

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

@awalker ,

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

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. 

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.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (20,127)