Power QueryExercises

Text.Contains

Text function · By Tahir Nas · Examples run in our simulator · Published · Updated

Tests whether text contains a substring.

When to use it

Use it to flag or filter rows by a keyword in free text, such as a description or a comment. Pass Comparer.OrdinalIgnoreCase unless case matters.

Syntax

Text.Contains(text as nullable text, substring as text, optional comparer as nullable function) as nullable logical

Parameters

comparer
Comparer.OrdinalIgnoreCase for case-insensitive matching.

Returns

true or false.

Example

Text.Contains("Rebill request", "BILL", Comparer.OrdinalIgnoreCase)

Result

true

Example: filter rows by keyword

Inside Table.SelectRows it keeps rows whose description mentions the word in any case.

Table.SelectRows(#table({"Desc"}, {{"Refund issued"}, {"New order"}, {"REFUND pending"}}), each Text.Contains([Desc], "refund", Comparer.OrdinalIgnoreCase))

Result

Desc
Refund issued
REFUND pending

Both results are produced by the Power Query Exercises simulator, an independent implementation of a documented subset of M, and checked on every build.

Good to know

Common mistakes

Exercises that use Text.Contains

Learn more

Related functions

Official documentation: Text.Contains on Microsoft Learn.