cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
indhaa
Super User
Super User

How to use With and Search function with an If condition

Hi,

 

I'm trying to use the Search using the With as given in this blog https://powerusers.microsoft.com/t5/Power-Apps-Community-Blog/With-Statement-to-include-non-Delegabl... by @WarrenBelz .

 

Having some issue since my Filter will change based on User . How to add the If condition to change the Filter 

 

If
(
  selectedNavItem = 2,
    SortByColumns(
              Filter(
              SPLIST, 
              RequesterDepartment=LogInUserDept),
              StartsWith(RequestTitle, searchInput.Text) ||                
              StartsWith(RequesterFullName, searchInput.Text) || 
              IsBlank(searchInput.Text)),
              "ID", Descending),
     
   	selectedNavItem = 3, 
	  SortByColumns( 
	   Filter(
             SPLIST, 
             RequesterEmail=LogInUserMail,
             StartsWith(RequestTitle, searchInput.Text)||             
             IsBlank(searchInput.Text)), 
	     "ID", Descending) 
	 
)

  I tried adding like below and I know it is not correct. 

With(
  If(selectedNavItem = 2,
   {
      MyFilter: 
      Filter(
         SPList,
         Department=LogInUserDept),
      
	},
	selectedNavItem = 3,
	{
      MyFilter: 
      Filter(
         SPList,
         Email=LogInUserMail),
      
	}
	),	
	
   Search(
      MyFilter,
      searchInput.Text,
      "FullName",
	  "Title"
   )
)

 

1 ACCEPTED SOLUTION

Accepted Solutions

@indhaa ,

A step back

With(
   {
      MyFilter: 
      If(
         selectedNavItem = 2,
         Filter(
            SPList,
            Department=LogInUserDept
         ),
         Filter(
            SPList,
            Email=LogInUserMail
         )
      )
   },
   Search(
      MyFilter,
      searchInput.Text,
      "FullName",
      "Title"
   )
)

You are also going to have to accept at times that you simply cannot do everything you want to do in a Delegable manner.

 

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

 

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @indhaa .

I am assuming the only choices for selectedNavItem are 2 and 3?

With(
   {
      MyFilter: 
      Filter(
         SPList,
         If(
            selectedNavItem = 2,
            Department=LogInUserDept,
            Email=LogInUserMail
         )
      )
   },
   Search(
      MyFilter,
      searchInput.Text,
      "FullName",
      "Title"
   )
)

 

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

I'm getting delegation warning on it. 

 

indhaa_0-1637318682226.png

 

@indhaa ,

A step back

With(
   {
      MyFilter: 
      If(
         selectedNavItem = 2,
         Filter(
            SPList,
            Department=LogInUserDept
         ),
         Filter(
            SPList,
            Email=LogInUserMail
         )
      )
   },
   Search(
      MyFilter,
      searchInput.Text,
      "FullName",
      "Title"
   )
)

You are also going to have to accept at times that you simply cannot do everything you want to do in a Delegable manner.

 

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

 

Yah, I don't think I will be able to use it.

 

Your above code is delegable but I need to add more condition which will not be delegable, so going to stick with my old code.

 

Thanks for the help

 

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.

Users online (1,326)