cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rizzle1
Frequent Visitor

Search, Filter a gallery based on any keyword in a sentence

Hey team,

 

Sorry just getting back into PowerApps and this is a simple one for some smart person out there!

 

Goal:

I have a gallery I'm trying to filter based off keywords I've set in a SharePoint list (HelpDeskHowTo).

 

Issue:

I've got it to work with search and filter but it will only work if my keyword appears as the first word in the text input box. If my keyword is "apply" then if i type "i want to apply" it wont show but just typing "apply" it will, if i type "Apply for" it will disappear. I need it to filter if my keyword shows up anywhere in the sentence

 

Examples below

 

This works

 

SS1.PNG

 

 

 

 

 

 

This doesn't

SS2.PNG

 

 

I've tried: 

Search(HelpDeskHowTo,DataCardValue1.Text, "Keywords")

Filter(HelpDeskHowTo, DataCardValue1.Text in Keywords)

 

Any help would be greatly appreciated 

1 ACCEPTED SOLUTION

Accepted Solutions
Rizzle1
Frequent Visitor

Ok I've managed to figure it out thanks to the information here

 

"There is no direct way to do what you want, but we can create an expression that could get to that. It will be something along the lines of:

Filter(
    Projects,
    Sum(
        ForAll(
            Filter(Split(SearchBox.Text, " "), Len(Trim(Result)) > 0),
            If(Result in Details, 1, 0)),
        Value) > 0)

Let's go through it. This sub-expression:

Filter(Split(SearchBox.Text, " "), Len(Trim(Result)) > 0)

It splits down your search text box into words, and also removes any empty words which you would get if you had two spaces between the words or leading or trailing spaces.

Then, for all words that were split, we see if that word is contained in the Details column of your list; if so we get the value 1, and 0 otherwise. The result of the ForAll sub-expression is a list of values corresponding to each the items in Projects. We then Sum those values. If any of the words from the search box were present in the details, then the sum will be greater than 0.

Finally we can filter the Projects based on that value, which should give you the result you want.

"

 

Filter(
HelpDeskHowTo,
Sum(
ForAll(
Filter(Split(searchQuery, " "), Len(Trim(Result)) > 0),
If(Result in Keywords, 1, 0)),
Value) > 0)

 

I think the combination of split and setting a number to a value if it matches then filtering off that has done the trick.

I've now set my text input box to set the searchQuery variable on change so its working beautifully

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @Rizzle1 ,

Firstly, both syntaxes you have supplied work if “apply” or part of it, is the only input in the text box, but please note neither are Delegable.

If I am reading your requirements right, you want to type apply, but then something after it and still have it match? It is not possible to have any “any part matches any part” search. Is this what you are meaning?

Thank you for the reply @WarrenBelz 

 

Thanks for the advice, I'm fine with these being non Delegable as I don't think my dataset will ever grow over 200 items

 

So I'm wanting the formula to be able to search the entire string looking for keywords not just the first word.

 

Example: I need to apply for leave

Apply is a keyword I've set on a list item as makeshift metadata. I want this item to show if apply is anywhere in the string

 

Currently it only works if I type apply by itself, if I put "apply for leave" (with a space and words after) it will no longer match and my recommendation disappears

Rizzle1
Frequent Visitor

Ok I've managed to figure it out thanks to the information here

 

"There is no direct way to do what you want, but we can create an expression that could get to that. It will be something along the lines of:

Filter(
    Projects,
    Sum(
        ForAll(
            Filter(Split(SearchBox.Text, " "), Len(Trim(Result)) > 0),
            If(Result in Details, 1, 0)),
        Value) > 0)

Let's go through it. This sub-expression:

Filter(Split(SearchBox.Text, " "), Len(Trim(Result)) > 0)

It splits down your search text box into words, and also removes any empty words which you would get if you had two spaces between the words or leading or trailing spaces.

Then, for all words that were split, we see if that word is contained in the Details column of your list; if so we get the value 1, and 0 otherwise. The result of the ForAll sub-expression is a list of values corresponding to each the items in Projects. We then Sum those values. If any of the words from the search box were present in the details, then the sum will be greater than 0.

Finally we can filter the Projects based on that value, which should give you the result you want.

"

 

Filter(
HelpDeskHowTo,
Sum(
ForAll(
Filter(Split(searchQuery, " "), Len(Trim(Result)) > 0),
If(Result in Keywords, 1, 0)),
Value) > 0)

 

I think the combination of split and setting a number to a value if it matches then filtering off that has done the trick.

I've now set my text input box to set the searchQuery variable on change so its working beautifully

Hi @Rizzle1 ,

Do you have any other problem?

If not, could you change your issue's status to "Answered"?

Thanks!

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

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