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

Filter Gallery by 2 Sorting Options

Hi PowerApps Community,

 

I have a gallery like below:

Rajeey3_0-1625060745797.jpeg

II would like to be able to sort the gallery by the two columns with the sort icons. I would like to be able to do this on an individual basis and not in conjunction with each other.

 

Here is my current code:

SortByColumns(
SortByColumns(
Search(
Filter(
SalaryData, Search_HR.Text,"cr666_name"),
"cr666_proposedpayrollsalary",If(SortDescending1,Descending,Ascending)),
"cr666_finalincrease",If(SortDescending101,Descending,Ascending))

 This always seems to sort on the proposed salary field and doesnt update for the final increase field.

 

I've also tried just putting them in the one SortByColumns as I know you can have it like this but again when I try to select the filter option for final increase there is no change and the proposed payroll salary still remains the one filtered.

 

Is there any way to achieve this?

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-jefferni
Community Support
Community Support

Hi @Rajeey3 ,

 

As you mentioned that you would like to be able to do this on an individual basis and not in conjunction with each other, then you will need 2 separate sort buttons to achieve their own purposes.

 

1\ sort button for proposedpayrollsalary OnSelect:

UpdateContext({SortDescending1:!SortDescending1});
UpdateContext({SortSalary:true})
UpdateContext({SortFinalIncrease:false})

 

2\ sort button for finalincrease OnSelect:

UpdateContext({SortDescending101:!SortDescending101});
UpdateContext({SortSalary:false});
UpdateContext({SortFinalIncrease:true})

 

3\ Formula for the Gallery:

If(SortSalary = true,
   SortByColumns(
                 Search(
                        SalaryData,
                        Search_HR.Text,
                        "cr666_name"
                 ),
                 "cr666_proposedpayrollsalary",
                 If(
                    SortDescending1,
                    Descending,
                    Ascending
                 )
   ),
   SortFinalIncrease = true,
   SortByColumns(
                 Search(
                        SalaryData,
                        Search_HR.Text,
                        "cr666_name"
                 ),
                 "cr666_finalincrease",
                 If(
                    SortDescending101,
                    Descending,Ascending
                 )
   ),
   Search(
          SalaryData,
          Search_HR.Text,
          "cr666_name"
   )
)

 

So, when clicking sort by salary, means not sort by final increase and vise versa. And if neither button has been clicked, only search for the name column without sorting.

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

3 REPLIES 3
v-jefferni
Community Support
Community Support

Hi @Rajeey3 ,

 

As you mentioned that you would like to be able to do this on an individual basis and not in conjunction with each other, then you will need 2 separate sort buttons to achieve their own purposes.

 

1\ sort button for proposedpayrollsalary OnSelect:

UpdateContext({SortDescending1:!SortDescending1});
UpdateContext({SortSalary:true})
UpdateContext({SortFinalIncrease:false})

 

2\ sort button for finalincrease OnSelect:

UpdateContext({SortDescending101:!SortDescending101});
UpdateContext({SortSalary:false});
UpdateContext({SortFinalIncrease:true})

 

3\ Formula for the Gallery:

If(SortSalary = true,
   SortByColumns(
                 Search(
                        SalaryData,
                        Search_HR.Text,
                        "cr666_name"
                 ),
                 "cr666_proposedpayrollsalary",
                 If(
                    SortDescending1,
                    Descending,
                    Ascending
                 )
   ),
   SortFinalIncrease = true,
   SortByColumns(
                 Search(
                        SalaryData,
                        Search_HR.Text,
                        "cr666_name"
                 ),
                 "cr666_finalincrease",
                 If(
                    SortDescending101,
                    Descending,Ascending
                 )
   ),
   Search(
          SalaryData,
          Search_HR.Text,
          "cr666_name"
   )
)

 

So, when clicking sort by salary, means not sort by final increase and vise versa. And if neither button has been clicked, only search for the name column without sorting.

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

@v-jefferni ,

 

Thank You this looks like a solution!!

I am probably asking a bit much but I have about 5 or 6 more filters in my code that I just left out of the post above to keep things simple. I am bit concerned performance wise of duplicating the code for each sort. 

Is there any way not to duplicate it?

 

Hi @Rajeey3 ,

 

Since it uses If statement to test which sort button is clicked, only one condition would be true then the only one evaluation for that condition would be working, there is no need to worry about the performance.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,118)