cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gavinleung
Resolver I
Resolver I

Compare a text with the text in a collection

Hi, 

 

I have a collection containing some text values:

Peter

Mary

John

 

And now I want to loop into the collection, and compare its text values with a text box value. If they match,  do A thing, otherwise do B thing. 

 

How can I compare these string values ? 

 

Thanks,

Gavin

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hey @gavinleung 

 

In that case, you can use the expression as:
 
If(TextInput1.Text in CollectionName.ColumnName, "Do A", "Do B")
 
If you need more help with the formula, please share more details so that we might be able to help you better.
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

9 REPLIES 9
yashag2255
Dual Super User II
Dual Super User II

Hey @gavinleung 

 

In that case, you can use the expression as:
 
If(TextInput1.Text in CollectionName.ColumnName, "Do A", "Do B")
 
If you need more help with the formula, please share more details so that we might be able to help you better.
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

Looks good. No error 🙂 Thanks!

 

oh sorry to ask one more point @yashag2255 

 

As there are multiple entries in the collection, I want to have the actions for every entry in the collection. Is this correct:

ForAll(
    myCollection, 
    If(Textbox1.Text in myCollection.Value,  
    "Do A", 
    "Do B")
    );

Does it make sense ? 

Hi @gavinleung ,


You're on the right track and what you've got should probably work Smiley Happy - but you can just refer to the myCollection column directly while you're in the scope of the ForAll - so;

ForAll(
    myCollection,
   If(Textbox1.Text in Value,
      "Do A",
      "Do B")
);

Also, "in" will match for strings and substrings case insensitive, so depending on your use case you may want to use a different operator.

eg:  Matching "Ian" against "Bian" would still match.  In this case, you may want to change your operator from "in" to "=" to be more specific.

Kind regards,

RT

Hey @gavinleung  to add to @RusselThomas 

 

myCollection.Value returns an array of specific column from all the items in the collection. If you wish to check for each item, you need to update the expression as:
 
ForAll(
    myCollection,
    If(Textbox1.Text in Value,
    "Do A",
    "Do B")
    );
 
Also, if you want to do updates on the collection itself, you can also try to use UpdateIf formula.
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

I tried using "=" before I wrote this post, but it turned out "invalid argument". 

Hey @gavinleung 

 

What is the type of Value attribute in your collection? I think there is a type mismatch, please share more details so that we might help you better.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi @yashag2255 

 

I used ClearCollect(_myCollection, [])

 

Does it declare any type ? 

Hey @gavinleung 

 

ClearCollect removes all the existing data and it will add the values passed in argument. You do not need to define datatypes, but to create the columns, you need to specify them and it will automatically set the data types for you, based on the data provided.
With the expression, ClearCollect(_myCollection, []) -> This will create a blank collection without any rows and columns.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (74,670)