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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,679)