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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Earl40
Helper I
Helper I

If statement to find word in a string

Hello,

 

I have a column that has a bunch of text in it. I want to create a custom column to search the text and if it sees certain words then enter that word.

 

Example: I want to search the text if it contains legal in it it then set value ad legal, if it contains Compliance then set value as compliance. I want to do this for 5 words. What foruma can I use in the custom column to do this?

 

Thank You 

 

?

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Earl40 it is a best practice to add a custom column in Power Query where possible, you can use the following M expression for a new custom column in PQ:

 

if Text.Contains([Column Name], "Legal") then "Legal" else if Text.Contains([Column Name], "2nd value" then "Some value" else "else value"

 read more about text.contains here Text.Contains - PowerQuery M | Microsoft Learn 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Is there a possibility of more than 1 keyword to appear in a sentence?  If yes, then what result would you expect.  Share some data to work with and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@Earl40 it is a best practice to add a custom column in Power Query where possible, you can use the following M expression for a new custom column in PQ:

 

if Text.Contains([Column Name], "Legal") then "Legal" else if Text.Contains([Column Name], "2nd value" then "Some value" else "else value"

 read more about text.contains here Text.Contains - PowerQuery M | Microsoft Learn 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.