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