cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Peter_L
Helper I
Helper I

Reversed contains function

Hey there,

 

I've been working all day on this but there must be a s uper easy solution.

I have an excel with multiple questions and answers. Questions are in one column, answers in another, yet another column contains a "catchword" describing the question (e.g. if the question is "what is Mars?" the catchword would be "Mars".

 

I now want to display the corresponding answer if the input contains the catchwork. 

So I don't want to filter the catchword column for the input but instead do the reverse - check if the input contains any of the catchwords in the catchword column. 

 

Any help would bbe very much appreciated! 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Peter_L 

 

If your body is the from value of your filter, then the expression is as follows:

 

indexof(triggerBody()?['text'],item()?['value'])

 

This will recursively check to see if each of the values from the body are in the text of the trigger body.  The expression will return an integer if the value appears or -1 if it doesn't.  Therefore your array will only return those that match and not equal to -1.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

View solution in original post

11 REPLIES 11
DamoBird365
Super User
Super User

Hi @Peter_L 

 

If I understand you correctly I think you want to use indexof.  This will allow you to check if a string is contained within another string.  If -1 is returned the answer is no, otherwise yes.  The only thing I don't quit get from your explanation is, what is the input interface?  

 

I have an example of the indexof in use here - look at the filter array.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

 

Peter_L
Helper I
Helper I

Thank you so much for the answer! In principle yes. To quickly explain the background: I'm using Power Virtual Agents as an input. If users ask a question and type it just a little different than it is saved in the excel sheet I still want them to see the answer. Hence the catchwords.
So if someone types "What is Mars" and "Define Mars" they would get the same answer since the question includes the catchword Mars.

@Peter_L 

 

Interesting project. 

 

Presumably you are using get rows from excel?  You can then use the the value in a filter array.

 

From the Value where indexof('the dynamic answer from PVA',item()?['catchword']) is not equal -1

 

This will return a new array where the answer matches.  If the length is greater than 0 you have a result, otherwise you don't.

 

I believe my logic from the article should work

 

DamoBird365_0-1621007368300.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Awesome, I will look into this. Thank you so so much! Really grateful. 

Peter_L
Helper I
Helper I

Hey @DamoBird365,

 

Sorry, it's still not quite working for me unfortunately.

I guess the issue is that there are multiple catchwords in the excel (one for each question/each row). 

 

So I want to check if a part of the array (one of the rows I got from excel / one of the catchwords) is contained in the input (the question typed in PVA). From what I've seen there is always an error when filtering for if a string contains an array - which is logically since that doesn´t make sense - but there must be a way to do this.

 

I typed in: 

indexof('triggerBody()['text']',items()?['outputs('List_rows_present_in_a_table')?['body/value']']) but it says that the expression is not valid. Any thoughts?
 
Peter

Hi @Peter_L 

 

If your body is the from value of your filter, then the expression is as follows:

 

indexof(triggerBody()?['text'],item()?['value'])

 

This will recursively check to see if each of the values from the body are in the text of the trigger body.  The expression will return an integer if the value appears or -1 if it doesn't.  Therefore your array will only return those that match and not equal to -1.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Hey there,

Thank you so much for your help.

 

I think I finally understand the reasoning. However, unfortunately I still get an error message because the second parameter is not of type string.

I tried typing it the way you did (the error message said that the second part was Null).

 

item()?['value']

 

I also tried using the dynamic content from the list rows step (Body and Value)

 

outputs('List_rows_present_in_a_table')?['body']
outputs('List_rows_present_in_a_table')?['body/value']

 

but both weren't value because they are not classified as strings. 

 

Maybe any step I need to put between Filter Array and List Rows?

 

 

Hi @Peter_L 

 

Can you share your flow as a screenshot or two and then show me where and what the error is?

 

Damien

 

 

Sure!

This is the general flow:

InkedScreenshot 2021-05-18 152306_LI.jpg

 

This is the error with the second parameter (of the index function) being "body" (see my last post):

Screenshot 2021-05-18 152359.png

 

 

And here is with the same being "value" (see my last post): Screenshot 2021-05-18 152507.png

 

Thank you so much!

Hi @Peter_L 

 

"Indexof(triggerbody()?['text']," is presumably all correct.  That is the string you want to search.  The 2nd part of the indexof expression is the value you want to search for.  Now, because we are using the result from list rows action, you need to call item()?['nameofthefield'].  You will be able to see the name of the field, in the history of the list rows actions.  Please expand the history and look at the outputs (click to download).  Then insert that name into the above expression.  You've used value which is presumably not the column name.  Let me know how you get on.

 

DamoBird365_0-1621432475919.png

 

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Peter_L
Helper I
Helper I

Thank you so so much! It finally works. This really means a lot to me!

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.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (2,620)