Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
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! 

  • Peter_L Profile Picture
    42 on at
    Re: Reversed contains function

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

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Reversed contains function

    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 Profile Picture
    42 on at
    Re: Reversed contains function

    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
    Re: Reversed contains function

    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
    Re: Reversed contains function

    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?

     

     

  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Reversed contains function

    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
    Re: Reversed contains function

    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
  • Peter_L Profile Picture
    42 on at
    Re: Reversed contains function

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

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Reversed contains function

    @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
    Re: Reversed contains function

    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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,700 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow