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 in collection w...
Power Apps
Answered

Search in collection with multiple keywords

(0) ShareShare
ReportReport
Posted on by 11

Hi

 

ClearCollect(

colTest,

{ ID: "1", Color: "black", Material: "metal", Size: "small", Type: "ball", Quantity: 40 },

{ ID: "2", Color: "yellow", Material: "plastic", Size: "big", Type: "ball", Quantity: 200 },

{ ID: "3", Color: "black", Material: "metal", Size: "medium", Type: "box", Quantity: 100 },

{ ID: "4", Color: "purple", Material: "glass", Size: "small", Type: "plate", Quantity: 100 })

 

probacska_1-1672950695920.png

 


I would like to make a searchbox with a multiple keywords search.

So, when I type "black metal small ball" to the searchbox -> I would like to get the ID: "1" row in the result.
When I type "black glass" to the searchbox -> I would like to get a blank result (and not the ID: "1", ID: "3", ID: "4" rows)

All words have to be AND connection.

I tried with this code, but it's not good.

 

ClearCollect(
colWords;
Split(
Trim(TextInput1.Text);
" "
)
);;
ClearCollect(
colResults;
Distinct(
Ungroup(
ForAll(
colWords;
Filter(
colProba;
colWords[@Result] in Color || colWords[@Result] in Material || colWords[@Result] in Size || colWords[@Result] in Type
)
);
"Value"
);
ID
)
);;
RemoveIf(
colResults;
Result = Blank()
);;
Clear(colFinal);;
ForAll(
colResults;
Collect(
colFinal;
First(
Filter(
colProba;
ID = Result
)
)
)
)

Categories:
  • WiZey Profile Picture
    3,023 Moderator on at

    Hello @probacska ,

     

    It should be possible after spending some brainpower, but first I'd like to ask why is it not possible to have three separate text inputs for the material, the color and the size?

  • probacska Profile Picture
    11 on at

    Hello WiZey!

    This is a sample collection, I use about 20 columns in the real project. I think it's easier to fill out one field than about 20 search fields and it also takes up little space.

  • Verified answer
    WiZey Profile Picture
    3,023 Moderator on at

    I tried something like this:

     

    With(
     { 
     _max: Max(
     cltTest4;
     Sum(
     ForAll(
     Split(
     TextInput6.Text;
     " "
     );
     {
     Value: If(
     Result = cltTest4[@Color];
     1;
     0
     ) + If(
     Result = cltTest4[@Material];
     1;
     0
     ) + If(
     Result = cltTest4[@Size];
     1;
     0
     )
     }
     );
     Value
     )
     )
     };
     Filter(
     cltTest4;
     IsBlank(TextInput6.Text) || Sum(
     ForAll(
     Split(
     TextInput6.Text;
     " "
     );
     Result in [
     cltTest4[@Color];
     cltTest4[@Material];
     cltTest4[@Size]
     ]
     );
     Value
     ) = _max
     )
    )

     

    It would take a bit of time to explain the logic here, but basically it check two things at once:

     

    First, the maximum count of validated conditions. If you type "purple glass", it will check if the record validate 2 conditions, but if you type "black glass" if will check if the record validate at least 1 condition.

    Second, it will check if said record has at least the text you've input by checking in a temporary table where I've stored the color, material and size. If "purple" is stored in a record, it will return it.

     

    Can you try with this and see how it goes?

  • probacska Profile Picture
    11 on at

    Thank you very very much!
    It works 😉

  • probacska Profile Picture
    11 on at

    This is your code, slightly modified:

    With(
     {
     _max: Max(
     colProba;
     Sum(
     ForAll(
     Split(
     Trim(TextInput1.Text);
     " "
     );
     {
     Value: If(
     Result in colProba[@Color] || Result in colProba[@Material] || Result in colProba[@Size];
     1;
     0
     )
     }
     );
     Value
     )
     )
     };
     Filter(
     colProba;
     IsBlank(TextInput1.Text) || Sum(
     ForAll(
     Split(
     Trim(TextInput1.Text);
     " "
     );
     Result in colProba[@Color] || Result in colProba[@Material] || Result in colProba[@Size] 
     );
     Value
     ) = CountRows(
     Split(
     Trim(TextInput1.Text);
     " "
     )
     )
     )
    )

     

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard