cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bees
Regular Visitor

Searching with multiple key words

Hi, I'm building an app that will eventually be a searchable databse of undergraduate theses. At the moment I'm using the template provided by powerapps which is actually very similar to the style of databse I had envisaged. 

 

I'm having an issue with the search box. Ideally I would like to be able to enter multiple search terms seperated by a comma or even just a space which returns all cases that contain these terms. The search function I have come up with based on information in these forums is:

SortByColumns(Search(Table1_1,TextSearchBox1.Text,"Abstract","Author","Supervisor(s)","Project_x0020_Title"),
"Year", If(SortDescending1, Descending, Ascending))

 

When I enter a term like "biofilm" in the box it searches the columns "Abstract","Author","Supervisor(s)" and "Project Title" and returns any case containing the word biofilm in these 4 columns.

 

This is great but ideally I would like to be able to enter multiple search terms in the text box, for example "biofilm", "Smith", "ecotoxicology" to return any cases which contain these three words. Is this possible to do in Powerapps? At the moment if I enter multiple terms and the words aren't consecutive then the search returns a blank. So for example if I enter "john" "smith", projects by john smith are returned; however if I enter "smith" "ecotoxicology" then there is no cases returned.

 

Thanks!

 

 

38 REPLIES 38
v-monli-msft
Community Support
Community Support

Hi @bees,

 

I'm afraid that this cannot be achieved so far in PowerApps. Please consider to add an idea here:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

Regards,

Mona Li

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
CalfordMath
Advocate V
Advocate V

This can be done with some creativity!  If you want to generate a collection of the records that contain ALL of the keywords you specify (in a textbox separated by a space, in my example) for a certain column, the code below will get what you seek:

Filter(
    CollectionName,
    IsBlank(
        Find(
            "0",
            Concat(
                Filter(
                    Split(
                        SearchBox.Text,
                        " " //or any delimiter.
                    ),
                    !IsBlank(ThisRecord.Value)
                ),
                If(
                    TrimEnds(ThisRecord.Value) in ColumnName1 || TrimEnds (ThisRecord.Value) in ColumnName2, // etc.
                    "1",
                    "0"
                )
            )
        )
    )
)

Here's what the code is doing:  Basically, we split the keywords you inputed using the space character as the delimiter (you could adjust this to be a comma or semicolon or whatever).  Then, for each record of the collection, we either include it or filter it out based on a string of zeros and ones we build, based on the keywords; "0" if a keyword is not found, and "1" if it is found.  We only want to include records that gave a string of all "1" 's.  So the condition on our filter is "IsBlank(Find("0", ....))  since the PowerApp Find function returns "Blank" (not 0) when a substring is not found.

If you wanted a collection of records that contain ANY of the keywords you specify, you could modify the Filter criteria from IsBlank(Find("0"...  to Find("1", ... ) > 0

I hope this helps someone!  While many features are not explicitly built into PowerApps (although the list is growing) it's kind of like they give us Yellow, Blue, and Red crayons from which we must blend all the colours we need for our drawing.  @v-monli-msft perhaps there as been a built-in way to search for multiple keywords since the OP asked this question in 2017, not sure.  Either way, it's fun to think of workarounds.

Hi

I have shared in Facebook in my group "Working with Powerapps" before.
Here is the sample and workable formula.

I use Split, Search, Filter, Last, First and TrimEnds and get exactly what clients want.
Simple and straight as all functions are explicitly self explanatory.

Please take note that you can enter keyword in any sequence. Not necessary to follow the fields sequence in the formula. It will search whatever matching keywords, and in partial. That's the reason I use search. You can modify to use IF and Number of columns to iterate so that formula becomes shorter.

My formula used for my client. Add more as necessary based on number of fields. Modify as you wish.

If(IsBlank(TextInput2), MyTable, Search(Search(Search(Search(MyTable, First(TrimEnds(Split(TextInput2.Text, ","))).Result, "Name", "City", "State", "Country"), Last(FirstN(TrimEnds(Split(TextInput2.Text, ",")), 2)).Result, "Name", "City", "State", "Country"), Last(FirstN(TrimEnds(Split(TextInput2.Text, ",")),3)).Result, "Name", "City", "State", "Country"), Last(FirstN(TrimEnds(Split(TextInput2.Text, ",")),4)).Result, "Name", "City", "State", "Country"))

Enjoy my sharing and have a nice day.

Thanks @PK_Hong for sharing!  That solution certainly works if you know both the number of keywords you wish to search for, and also the number of results you wish to display.  I love the First(LastN( way of indexing the results, I've used that as well in many situations!  I prefer a dynamic approach, where the number of keywords is not limited and the returned result is the entire collection of all records that contained the keywords (rather than only the top N).  These could be displayed in a listbox or gallery.  But like all code.. if it works for your purposes it's the right code!

HI @CalfordMath 

 

Hi Thanks for sharing of info.

As I mentioned, you can use n= n+1 iteration to make it more user friendliness. I love your way of writing which serves for one fields.

Maybe you can also try mines which is Multi Fields, Multi Keywords and instant (I use my own custom connector, not SPL or CDS).

 

I wish you can integrate mine and make it better and share here. I am more than happy to use a shorter and better codes from others with sharing.

 

Best wishes

Additional Notres

 

Even it is N fields, all keywords are searched for... it has no limit!

The only limitation is if you have more fields, you need to add more "field name".

 

Anyway this is my initial formula.

For my own, I am using dynamic iteration. I do not need to add one by one

So this is for veryone to expand ideas.

 

Thanks so much for sharing.

True @PK_Hong my solution was only for a single field search.  It could be modified with a simple "Or" to look at more fields:

TrimEnds(Result) in Column1 ||TrimEnds(Result) in Column2 || TrimEnds(Result) in Column3 ...

It would be really nice if the Search function allowed us to pass a collection of strings, rather than just a single string.  I suppose it would need to be told whether to report records containing 'any' or 'all' of the search terms.  I haven't tried to re-work your method using an iterative approach, but when I have some time I'll give it a go.

 

I was looking to see if there was way to search in all columns rather than having to explicitly list each one by name... no such luck, but in the process, I did discover that using the "in" operator for a sub-string test is case-insensitive, which means I probably could remove the Lower() calls from my code to clean it up a bit.

It is a pleasure talking through these ideas with you!  I love how the PowerApps community shares workarounds and tricks.  The platform is still so young and growing.. it's fun to be near the forefront of something 😉

 

This was an absolute lifesaver! I've been searching for days, literally and kept coming across a link referenced on these forums that has access denied. It's crazy to me how much simpler these formulas are than those I was experimenting with. I have never worked with the TrimEnds operator before, nor would've thought about identifying the results with a 1 or 0. Anyway, I can't thank you both enough for providing your solutions!

@CalfordMath - After implementing your solution I'm just now realizing that I need to also have something so that it knows which row I select with a filtered result. I didn't realize (as I wasn't focused on the actual data) that when I click on a row that's filtered from this search it always shows me the first row in the gallery. Obviously this is NOT what we want for the behavior. My form is currently doing a lookup to the selected gallery item - Lookup(datasource, ID = gallery.selected.id), but with using the TrimEnds(Result) function I'm guessing we need to have something in the form that looks to that result vs what I have in there. Things work fine for selecting an item in the gallery if I don't use search to filter, but we need to have it show the selected item in either case.

 

*EDIT* to clarify I am seeing the right one for a split second on the form screen but it changes back to the first row item. So, something is causing the form to then go to the first item in the list.

 

Your help is greatly appreciated!

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Top Solution Authors
Top Kudoed Authors
Users online (2,788)