CONTAINSSTRING

The CONTAINSSTRING function returns True if the string within_text included as the first argument contains the text find_text string included as the second argument.

Syntax

CONTAINSSTRING(
    within_text,
    find_text
)

Parameters
  • within_text: Text in which to search.
  • find_text: Text to search.
Returned value

The CONTAINSSTRING function returns a Boolean.

Additional Information

This function is not case sensitive. Is it possible to use the symbol ? to represent any character and the * symbol to represent any set of characters. On the other hand, the ~ symbol serves to "escape" the previous symbols (that is, if we really want to search for an asterisk, we can do so by searching for "~*" ).

Examples

In this first example we do simple searches after creating a calculated column with the following function:

Búsqueda = CONTAINSSTRING(Textos[Texto], Textos[Texto a buscar])

CONTAINSSTRING function

We see that, indeed, the function is not case-sensitive.

In this second example we make use of the wildcards:

CONTAINSSTRING function

In the first line we look for the letter "e" followed by any other character, which is found several times in the text "Business Intelligence". However, in the second line we look for the string "ce" (found in the text) followed by a character (which is not the case), returning the value False .

Searching for an "a" followed by a character in the text "Power BI" returns False (in fact, there is no "a" in that text).

In "Machine Learning" we look for an "a" and an "e" that may or may not have characters between them, what is found. Note that in the following search, also on the text "Machine Learning", an "e" and an "a" are searched with characters or not between them. This combination exists ("learning") with no characters, and returns True as the wildcard * does not require the existence of characters.

In the text "Deep Learning" we look for an "a" followed by an "e" (with or without characters between them), which does not exist, so False is returned.

And the last two rows look for a question mark. In the first of the two, True is returned as the question mark is interpreted as a wildcard that represents any character (what is found), which does not have to be what we are looking for (we could be looking for a question mark in our string of text). In the second example we "escaped" the question mark by forcing Power BI to literally search for this symbol in the text string.

If the text string to search on is an empty text string, the function returns an error:

CONTAINSSTRING function
Related functions
Category
Text
Submitted by admin on Fri, 04/05/2019 - 10:24