cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AuburnMist
Helper IV
Helper IV

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
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,497)