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.
Solved! Go to Solution.
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.
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.
@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.
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.