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.

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.

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

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

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,566)