Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Tobias2019
Regular Visitor

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

1 ACCEPTED SOLUTION
VasTg
Memorable Member
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.

 

VasTg_0-1572449707164.png

 

Let us know if this helps.

Connect on LinkedIn

View solution in original post

5 REPLIES 5
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

gooranga1
Power Participant
Power Participant

hi @Tobias2019 

 

looks like you have missed a [ at the start of the field name.

 

bracket.png

@gooranga1 

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

VasTg
Memorable Member
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.

 

VasTg_0-1572449707164.png

 

Let us know if this helps.

Connect on LinkedIn

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

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.