cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AuburnMist
Resolver I
Resolver I

How to add Filter to SortbyColumns and Search

Hello, 

 

I have a gallery that currently has the following code in the Items property:

 

SortByColumns(Search(TEMPO_Leave,drpEmployeeEmail.SelectedText.Value,"EmployeeEmail"),"StartDate",If(SortDescending,Descending,Ascending))

 

The above code makes the gallery display only the records belonging to the selected employee (according to their email), and sort by StartDate. 

 

The gallery displays employee leave information. I would like to include filters to allow the user to filter by leave type and by status but I don't know how to add a Filter function to the above code. 

 

 

 

AuburnMist_1-1652294156962.png

 

Thank you for your help. 

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @AuburnMist ,

Firstly why are you using Search when the email will be an exact match ? You could do this (note I have assumed your drop-downs are Choice values or .Value will be different)

SortByColumns(
   Filter(
	  TEMPO_Leave,
      (
         Len(YourLeaveTypeDD.Selected.Value) = 0 ||
         'Leave Type' = YourLeaveTypeDD.Selected.Value
      ) &&
         Len(YourStatusDD.Selected.Value) = 0 ||
         Status = YourStatusDD.Selected.Value
      ) &&
      EmployeeEmail = drpEmployeeEmail.Selected.Value
   ),
   "StartDate",
   If(
      SortDescending,
      Descending,
      Ascending
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

Hi Warren,

 

I cannot get your code to work. 😞 

 

The reason why I used "Search" to find the correct employee is because "Filter" does not provide the expected result (it displays the records for ALL of the employees). The email of the correct employee doesn't come from a dropdown (Choice column), it comes from a table I created as a SharePoint list (separate list from TEMPO_Leave) - perhaps that is the reason? 

 

Please see these screenshots:

1) With existing code: 

AuburnMist_0-1652307532942.png

2) With "Search" changed to "Filter"

AuburnMist_1-1652307610122.png

3) With the code you provided MINUS the EmployeeEmail part: 

AuburnMist_2-1652308325152.png

4) With the full code you provided: 

AuburnMist_3-1652308986205.png

 

Hi @AuburnMist ,

I did know your field types and assumed Text - I suspect now they are Choice columns - also if you want to search (but I am still confused why you are Searching

SortByColumns(
   Filter(
	  TEMPO_Leave,
      (
         Len(YourLeaveTypeDD.Selected.Value) = 0 ||
         'Leave Type'.Value = YourLeaveTypeDD.Selected.Value
      ) &&
         Len(YourStatusDD.Selected.Value) = 0 ||
         Status.Value = YourStatusDD.Selected.Value
      ) &&
      drpEmployeeEmail.Selected.Value in EmployeeEmail 
   ),
   "StartDate",
   If(
      SortDescending,
      Descending,
      Ascending
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

WarrenBelz
Super User
Super User

Hi @AuburnMist ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Hi Warren, 

I could not resolve this matter, but I opted to not add the filter in the end on account that managers will be able to get the information through their accompanying PowerBI report. 

Thank you for your support though. 🙂

Helpful resources

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

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (4,785)