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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
galbatrox9
Helper I
Helper I

Power Query M formula not working ( Nested IF with and)

Hi Team,

 

I am trying to add a custom column based on two columns. I want the new column to tell me all rows where the Subject contains "trade" and "fail" but Contacts does not contain no-reply@123.com.

 

if (Text.Contains([Subject],"trade"))
and (Text.Contains([Contacts],"no-reply@123.com"))
and (Text.Contains([Subject],"fail"))
and not Text.Contains([Subject],"scheduled")
then "Trade Failure"
else ""

 

 

But the output is blank. When i run the code without the and not line, its working (but obviously not pulling what i want).

 

 

1 ACCEPTED SOLUTION

I just tried this and it worked .

 

if (Text.Contains([Subject],"trade"))
and (Text.Contains([Subject],"fail"))
and (
    (Text.Contains([Contacts],"noreply@123.com"))
or 
(Text.Contains([Contacts],"no-reply@123.com"))
)

and not (Text.Contains([Subject],"scheduled"))
and not (Text.Contains([Subject],"re:"))
then "Trade-In Failure"

else if (Text.Contains([Subject],"scheduled"))
and (Text.Contains([Subject],"fail"))
and (
    (Text.Contains([Contacts],"noreply@123.com"))
or 
(Text.Contains([Contacts],"no-reply@123.com"))
)

and not (Text.Contains([Subject],"trade"))
and not (Text.Contains([Subject],"re:"))
then "Report Failure"

else ""

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

What if you try:

 

IF (Text.Contains([Subject],"scheduled"), "", 

if (Text.Contains([Subject],"trade"))
and (Text.Contains([Contacts],"no-reply@123.com"))
and (Text.Contains([Subject],"fail"))

Well there is another IF that i was wanting to nest into it so this wont work.

 

This is the currently the code with the nested if, but it doesn't work. 

 

if (Text.Contains([Subject],"scheduled"))
and (Text.Contains([Contacts],"no-reply@123.com"))
then "Report Failure"

else if (Text.Contains([Subject],"trade"))
and (Text.Contains([Subject],"fail"))
and (Text.Contains([Contacts],"no-reply@123.com"))
then "Trade Failure"

 

I just tried this and it worked .

 

if (Text.Contains([Subject],"trade"))
and (Text.Contains([Subject],"fail"))
and (
    (Text.Contains([Contacts],"noreply@123.com"))
or 
(Text.Contains([Contacts],"no-reply@123.com"))
)

and not (Text.Contains([Subject],"scheduled"))
and not (Text.Contains([Subject],"re:"))
then "Trade-In Failure"

else if (Text.Contains([Subject],"scheduled"))
and (Text.Contains([Subject],"fail"))
and (
    (Text.Contains([Contacts],"noreply@123.com"))
or 
(Text.Contains([Contacts],"no-reply@123.com"))
)

and not (Text.Contains([Subject],"trade"))
and not (Text.Contains([Subject],"re:"))
then "Report Failure"

else ""

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors