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:
"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.
I'm afraid that this cannot be achieved so far in PowerApps. Please consider to add an idea here:
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(Result) ), If( TrimEnds(Result) in ColumnName1 || TrimEnds (Result) 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.
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 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.
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!
The Super User program for 2022 - Season 2 has kicked off!
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.