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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Alicia_Anderson
Resolver I
Resolver I

Help with Power Query custom column with multiple conditions and Text.Contains

I am trying to create a Custom Column in Power Query that looks for a text string in any of three different text fields.  My main issue is that any of the fields may contain a null value and this is causing errors.   

 

For example:  I want to set a new column, IsRelease, to "Y" if Release1 or Release2 or Release3 contains "ABC" else set to "N".

 

Release1Release2Release3IsRelease
ABCnullnullY
ABCXYZnullY
ABCnullABCY
XYZABCDEFY
nullnullABCY
nullnullnullN
XYZnullXYZN

 

I need help with the proper way to write this...

 

If (Release1 Text.Contains "ABC" or

Release2 Text.Contains "ABC" or

Release 3 Text.Contains "ABC" ) then "Y", else "N"

 

1 ACCEPTED SOLUTION

Hi @Alicia_Anderson ,

 

Try this instead:

try
if Text.Contains([Release1], "ABC")
    or Text.Contains([Release2], "ABC")
    or Text.Contains([Release3], "ABC")
then "Y"
else "N"
otherwise "N"

 

This gives the following output:

BA_Pete_0-1647587226927.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

Hi @Alicia_Anderson ,

 

Try this:

if Text.Contains([Release1], "ABC")
    or Text.Contains([Release2], "ABC")
    or Text.Contains([Release3], "ABC")
then "Y"
else "N"

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




That is what I have.  Any row that has a null in one of those fields produces an Error.

If I change the nulls to "" beforehand, it works without a problem.    Not sure what problems or concerns there may be with doing that.

Hi @Alicia_Anderson ,

 

Try this instead:

try
if Text.Contains([Release1], "ABC")
    or Text.Contains([Release2], "ABC")
    or Text.Contains([Release3], "ABC")
then "Y"
else "N"
otherwise "N"

 

This gives the following output:

BA_Pete_0-1647587226927.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.