Forum Discussion
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
?
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
2 Replies
- parry2k
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
- Ashish_Mathur
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.