Forum Discussion

Tobias2019's avatar
Tobias2019
Regular Visitor
6 years ago
Solved

If - else function with two Text.Contains functions combined with "and"

Dear all,

 

I try to achieve a combination of Text.Contain statements, but I fail with that. I don't know where to look at, maybe you do have an idea.

 

I have got following structure in my table:

 

Interface nameError statement
Interface appleThere is a mismatch
Interface bananaThere is a mismatch

 

The relevant part of the statement looks like this:

if (Text.Contains(Error Statement], "There is a mismatch") and Text.Contains([Interface name] = "apple")) then "Result 1"
else if (Text.Contains(Error Statement], "There is a mismatch") and Text.Contains([Interface name] = "banana")) then "Result 2"

 

 

 

The error message which I receive is:

An error occurred in the ‘xxx’ query. Expression.Error: The field 'Interface name' of the record wasn't found.

 

Thank you in advance,

Tobias

  • Tobias2019 

     

    I was able to create a new column for the specified condition with final else condition. Make sure to use the correct column names.

     

     

    Let us know if this helps.

5 Replies

  • VasTg's avatar
    VasTg
    Memorable Member

    Tobias2019 

     

    I was able to create a new column for the specified condition with final else condition. Make sure to use the correct column names.

     

     

    Let us know if this helps.

    • Tobias2019's avatar
      Tobias2019
      Regular Visitor

      VasTg: Thanks your reply. In your screenshot I noticed something, which I was doing wrong: I used a "=" instead of a "," in the second statement. But still I receive this error message:

       

      An error occurred in the ‘xxx’ query. Expression.Error: The field 'Interface name' of the record wasn't found.

       

      One more information which I missed to provide: My if-else contains several loops. Only two of them are extended with an "and" clause.

      Do you think Power BI might have an issue in this regard?

    • Tobias2019's avatar
      Tobias2019
      Regular Visitor

      gooranga1 

      Thanks for you reply. This was only a copy&paste issue. I copied my original statement and replaced the values with some samples.

  • Tobias2019's avatar
    Tobias2019
    Regular Visitor

    Hello together,

     

    I managed to solve the issue.

    The statement of VasTg is correct!

    In my special case, I had a formatting issue in the column, which I used for the second statement (Interface name). Although I used the Text.Contains function and only searched to a small part of the text, the query brought up errors.

    Now I used another column containing similar information and here it works.

     

    Anyone else having the same problem: Use the query how VasTg buildt it. If you fail, first try to use another column to check, if the query is the problem or your data format.

     

    Topic solved!

     

    Thanks & regards,

    Tobias