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 Automate / Reversed contains func...
Power Automate
Answered

Reversed contains function

(0) ShareShare
ReportReport
Posted on by 42

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! 

Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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 Profile Picture
    42 on at

    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.

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    @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 😉

  • Peter_L Profile Picture
    42 on at

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

  • Peter_L Profile Picture
    42 on at

    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
  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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 😉

  • Peter_L Profile Picture
    42 on at

    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?

     

     

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @Peter_L 

     

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

     

    Damien

     

     

  • Peter_L Profile Picture
    42 on at

    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!

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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 😉

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard