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

Sort dropdown values in a Gallery

I would like to Sort a dropdown value (STATUS) in the Gallery below where the sort direction will be dynamic and be based on the icon beside the column header name. 

 

The icon image changes to Ascending or Descending when the user clicks on it.

 

genarich_1-1642193711642.png

 

Sort(
    Search(
        Filter(
            col_YQQ,
            If(
                Gallery1.Selected.Filter = "ALL OPEN ORDERS",
                Status.Value <> "Completed" && Status.Value <> "Cancelled"
            )
        ),
        TextInput12_5.Text,
        "Part_x0023_Requested"
    ),
    "OrderStatus",
    If(
       varSortDirection = Ascending,
       Ascending,
       Descending
     )
)

 

 

 

I was able to do it with the TEXT column values but it seems to not work with the DROPDOWN value field.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@genarich 

I assume then that the OrderStatus column is a Choice column.  If so, then consider the following formula for your Items property of the gallery:

Sort(
    AddColumns(
      Search(
        Filter(
          col_YQQ,
          (Gallery1.Selected.Filter = "ALL OPEN ORDERS" && Status.Value <> "Completed" && Status.Value <> "Cancelled") ||
          !(Gallery1.Selected.Filter = "ALL OPEN ORDERS")          
        ),
        TextInput12_5.Text,
        "Part_x0023_Requested"
      ),
      "_status", Status.Value
    )
    _status,
    If(varSortDirection = Ascending, Ascending, Descending)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

6 REPLIES 6
RandyHayes
Super User
Super User

@genarich 

I assume then that the OrderStatus column is a Choice column.  If so, then consider the following formula for your Items property of the gallery:

Sort(
    AddColumns(
      Search(
        Filter(
          col_YQQ,
          (Gallery1.Selected.Filter = "ALL OPEN ORDERS" && Status.Value <> "Completed" && Status.Value <> "Cancelled") ||
          !(Gallery1.Selected.Filter = "ALL OPEN ORDERS")          
        ),
        TextInput12_5.Text,
        "Part_x0023_Requested"
      ),
      "_status", Status.Value
    )
    _status,
    If(varSortDirection = Ascending, Ascending, Descending)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I copied the code exactly as how you mentioned. But the ICON.SORT arrows up and down when clicked did not change the sort to either ascending or descending.

 

I also tried replacing both the "_status" with the exact name field from SP List. However, an error is saying that a column name already exists.

 

genarich_0-1642204281776.png

RandyHayes
Super User
Super User

@genarich 

First, do not change the name of the _status.  That is an added column that is integral to your sorting.

Next, what is the OnSelect action formula of your Icon?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Here it is:

 

Set(
    varSortColumn,
    "OrderStatus"
);
Set(
    varSortDirection,
    If(
        varSortDirection = Ascending,
        Descending,
        Ascending
    )
)

 

RandyHayes
Super User
Super User

@genarich 

Then, based on that formula, your formula for the Items should be:

Sort(
    AddColumns(
      Search(
        Filter(
          col_YQQ,
          (Gallery1.Selected.Filter = "ALL OPEN ORDERS" && Status.Value <> "Completed" && Status.Value <> "Cancelled") ||
          !(Gallery1.Selected.Filter = "ALL OPEN ORDERS")          
        ),
        TextInput12_5.Text,
        "Part_x0023_Requested"
      ),
      "_status", Status.Value
    )
    _status,
    varSortDirection
)

 

However, it appears that you are also setting a sort column in that OnSelect formula.  In your original formula you had hard coded that value in and not referenced the variable.

Are you trying to be able to sort by a variety of columns or is it all just by Status now?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I finally made it work! Thank you!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,369)