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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Search in collection w...
Power Apps
Unanswered

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:
I have the same question (0)
  • 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard