cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RameshMukka
Post Prodigy
Post Prodigy

Sort PowerApps Gallery using Status Choice Column

I have Status column in my SharePoint List with Choices New, In Progress and Completed. In my gallery I would like to show items sorted with this column. The "Completed" items needs to be at the end of the gallery. I would like to sort in the order of In Progress, New and Completed. I am not finding a way to do this for a choice column. What should be my approach for this? Below code is what I got for my Gallery items. 

 

SortByColumns(
    Filter(
        'SLD Form',
        (Category.Value = drpCategory.Selected.Value || If(
            drpCategory.Selected.Value = "All",
            true,
            false
        )) && (TopicType.Value = drpTopicType.Selected.Value || If(
            drpTopicType.Selected.Value = "All",
            true,
            false
        )) && (Status.Value = drpStatus.Selected.Value || If(
            drpStatus.Selected.Value = "All",
            true,
            false
        )) && If(
            varShowUpcmg,
            Schedule >= varToday,
            true
        )
    ),
    "Schedule",
    Descending
)

  

Also I dont think I would be able to use AddColumns Function as my gallery is linked to EditForm where there can arise conflict. I am really running out of options.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@RameshMukka 

Please consider changing your Formula to the following:

DropColumns(
    SortByColumns(
        AddColumns(  
            Filter(
                'SLD Form',
                (drpCategory.Selected.Value = "All" || Category.Value = drpCategory.Selected.Value) &&
                (drpTopicType.Selected.Value = "All" || TopicType.Value = drpTopicType.Selected.Value) &&
                (drpStatus.Selected.Value = "All" || Status.Value = drpStatus.Selected.Value) &&
                ((varShowUpcmg && Schedule >= varToday) || !varShowUpcmg)
            ),
            "_sortOrder", Switch(Status.Value, "In Progress", 1, "New", 2, "Completed", 3, 4)
        ),
        "_sortOrder",
        Ascending
     ),
     "_sortOrder"
)     

In the above (first the filter criteria is simplified), the column is added for the sort order.  Then the list is  sorted by that column.  Finally, since you have dependency on the schema of the Gallery records, the column is dropped.

 

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

3 REPLIES 3
RandyHayes
Super User
Super User

@RameshMukka 

Please consider changing your Formula to the following:

DropColumns(
    SortByColumns(
        AddColumns(  
            Filter(
                'SLD Form',
                (drpCategory.Selected.Value = "All" || Category.Value = drpCategory.Selected.Value) &&
                (drpTopicType.Selected.Value = "All" || TopicType.Value = drpTopicType.Selected.Value) &&
                (drpStatus.Selected.Value = "All" || Status.Value = drpStatus.Selected.Value) &&
                ((varShowUpcmg && Schedule >= varToday) || !varShowUpcmg)
            ),
            "_sortOrder", Switch(Status.Value, "In Progress", 1, "New", 2, "Completed", 3, 4)
        ),
        "_sortOrder",
        Ascending
     ),
     "_sortOrder"
)     

In the above (first the filter criteria is simplified), the column is added for the sort order.  Then the list is  sorted by that column.  Finally, since you have dependency on the schema of the Gallery records, the column is dropped.

 

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!

@RandyHayes  You are genius sir! It worked like a charm. Thank you so much. I have one more question regarding your formula. I have seen delegation warning regarding the filter i used for my date column "Schedule". But with your formula I dont see that. I didn't understand how? Can you explain a bit.

RandyHayes
Super User
Super User

@RameshMukka 

No problem!

Yes, in your original formula you were using If's to determine variables and then doing criteria on Schedule.  This is not something that PowerApps can delegate, and thus the delegation warning.  In my formula, we just delegate the criteria and then we can AND that with the variable OR the NOT of the variable.  Result is the same, but PowerApps can delegate that.

_____________________________________________________________________________________
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!

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Solution Authors
Top Kudoed Authors
Users online (1,782)