cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bassman99
Helper I
Helper I

Browse Gallery: Use "If()" statement inside Search() function?

Question:  Is it possible to use the If() statement inside a Search() function?

 

I start with a basic search:

SortByColumns(Search([@'MyTable'],TextSearchBox1.Text,"Title"),"Title",If(SortDescending1,Descending,Ascending))

[Note: I realize there is a delegation issue...].

 

What I want to do is substitute an "if()" statement for "[@'MyTable']", which:

  • Simply returns "[@'MyTable']" if "" is selected in a drop-down (ComboBox_Request_Status.Selected.Value).
  • Returns "Filter([@'MyTable'], Request_Status=ComboBox_Request_Status.Selected.Value)" if a non-blank value is selected from the drop-down (ComboBox_Request_Status.Selected.Value).

I can't tell if A) use of "if()" in a search formula is not allowed or B) I just have a syntax error somewhere.

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @bassman99 ,

Try this

SortByColumns(
   Filter(
      [@'MyTable'],
      Len(TextSearchBox1.Text) = 0 ||
      TextSearchBox1.Text in Title
   ),
   "Title",
   If(
      SortDescending1,
      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

View solution in original post

2 REPLIES 2
WarrenBelz
Super User
Super User

Hi @bassman99 ,

Try this

SortByColumns(
   Filter(
      [@'MyTable'],
      Len(TextSearchBox1.Text) = 0 ||
      TextSearchBox1.Text in Title
   ),
   "Title",
   If(
      SortDescending1,
      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

That's *IT*!  The "trick" is to use and/or with Filter, not an if() statement!  My final formula was this:

SortByColumns(
Filter(
[@'MyTable'],
(Len(TextSearchBox1.Text) = 0 || TextSearchBox1.Text in Title),
(Len(ComboBox_Request_Status.Selected.Value) = 0 || Request_Status=ComboBox_Request_Status.Selected.Value)
),
"Title",
If(
SortDescending1,
Descending,
Ascending
)
)

 

Thanks!!

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 (4,166)