web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Search within an If fu...
Power Apps
Unanswered

Search within an If function

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I'm having some trouble searching a data table by various text inputs depending on certain circumstances. For example, I want to search the table by 'SearchBar1'.Text when a button is pushed, but by 'SearchBar2'.Text when the button is turned off. The following formula mirrors that in my app:

 

If( filterbuttonpressed,
       Search('Table1', 'Search Bar1'.Text, "column1"),
      Search('Table1', 'Search Bar2'.Text, "column1", "column2", "column3", "column4", "column5"))
   )

 

I'm not getting an error with this code, but when filterbuttonpressed = true, I get no results when searching text through Search Bar 1 (and there should be records corresponding to my search text). 

 

Does the search function not work within an If function?

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous 

    How do you turn a button off in PowerApps?  If you have a checkbox instead, make the Items property of the data table: If(Checkbox1.Value, Search('Table1', 'Search Bar1'.Text, "column1"),

     

    If(
     Checkbox1.Value, Search(Table1,'Search Bar1'.Text,'column1'),
     Search(
     'Table1','Search Bar2'.Text,"column1", "column2", "column3", 
     "column4", "column5"
     )
    )

     

    The same formula would hold for a Toggle control, just substitute Toggle1.Value for Checkbox1.Value in the above formula.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Appreciate the above. However, "filterbuttonpressed" is just a variable that is toggled on and off when the filter button is pressed (OnSelect = UpdateContext({filterbuttonpressed: !filterbuttonpressed}). Regardless, I've modified the formula a bit to incorporate additional filter fields, but I'm not having much luck:

     

    If ( filterbuttonpressed ,

            Filter ('Table1', StartsWith("column1", 'SearchBar2'.Text) || StartsWith("column2", 'SearchBar3'.Text) ||    StartsWith("column3", 'SearchBar4'.Text)),

           Search ('Table1', 'SearchBar1'.Text, "column1", "column2", "column3", "column4", "column5")

        )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard