In Power Query, you can use the Text.Contains function to test whether a substring is in a string or not. Apart from this function, we can also use the IF statement to test for a substring.
In the below example, we have a list of names with the suffix for male and female. And we need to check which are the names with the female suffix.

Using Text.Contains in Power Query
- Go to the Data Tab > Get Data > From Other Sources > From Table/Range.

- Now, go to Add Column > Custom Column in the Power Query editor.

- From here, in the Custom Column dialog box, enter a name for the new column, and in the formula box, enter Text.Contains([Names],”Ms.”) after the equal sign that is already there.

- In the end, click OK to add the columns.
When you click OK, it will add a new column with TRUE and FALSE: TRUE where the text contains “Ms.” and FALSE for the rest.

How this Function Works
In the function, you have two arguments to define. In the first argument (text), you specify the column with the main text in which you want to check the condition.
And in the second argument (substring), you need to specify the substring which you want to look for in the main string of the first argument. There’s also an optional third argument (comparer), which you can use to ignore the case (see below).

Use IF to Check Text Contains
You can also use the IF statement to check if a text contains another text. By using IF, you can use meaningful results instead of TRUE and FALSE. So, in the Power Query editor, you need to go to the Add Column tab and click Conditional Column.

When you click on the Conditional Column, it will show a dialog box to create an IF statement.

Here you need to:
- Enter the Column Name.
- Select the column name to check the condition.
- Select the operator “contains”.
- Value to check, “Ms.”.
- Output to get if the condition is TRUE, “Female”.
- And output to get if the condition is FALSE, “Male”.
- In the end, click OK to enter the column.
The moment you click OK, you will get a new column which has “Female” where the text contains “Ms.” and “Male” for the rest.
Behind the scenes, the Conditional Column writes this formula, which you can also enter yourself in a custom column:
if Text.Contains([Names], "Ms.") then "Female" else "Male"
In the end, go to Home ➜ Close & Load to load the result back to the worksheet.

Ignore Case with Text.Contains
Text.Contains is case-sensitive. So, “ms.” in lowercase doesn’t match “Ms.”. If you want to ignore the case, add Comparer.OrdinalIgnoreCase as the third argument:
Text.Contains([Names], "ms.", Comparer.OrdinalIgnoreCase)
And if the column has empty (null) cells, Text.Contains returns null for those rows. To get FALSE instead, check for null first:
if [Names] = null then false else Text.Contains([Names], "Ms.")
Check for More Than One Text
To check if a cell contains any one of several texts, like “Ms.” or “Mrs.”, combine Text.Contains with List.AnyTrue and List.Transform in a custom column:
List.AnyTrue(List.Transform({"Ms.", "Mrs."}, each Text.Contains([Names], _)))
It returns TRUE when the name contains at least one of the texts in the list. Use List.AllTrue instead if the name must contain all of them.
Filter Rows That Contain a Text
If you don’t need a new column and only want to keep the rows that contain a text, click the filter button on the column header, go to Text Filters ➜ Contains, enter “Ms.” and click OK. Power Query adds a Filtered Rows step that uses Text.Contains behind the scenes.
Frequently Asked Questions
Why do I get an error with Text.Contains?
The usual reasons are writing the name in the wrong case (M is case-sensitive, so it must be Text.Contains, not TEXT.CONTAINS) or using it on a column with numbers. For numbers, convert them first with Text.From([Column]).
How do I check if a text starts or ends with a value?
Use Text.StartsWith or Text.EndsWith. They take the same arguments as Text.Contains, like Text.StartsWith([Names], “Ms.”).
Is the contains operator in the Conditional Column case-sensitive?
Yes. The Conditional Column writes a Text.Contains formula, so “ms.” and “Ms.” are different. Use a custom column with Comparer.OrdinalIgnoreCase if you need to ignore the case.