SEARCH DAX Function (Text)

Returns the starting position of one text string within another text string. SEARCH is not case-sensitive, but it is accent-sensitive.

Syntax

SEARCH ( <FindText>, <WithinText> [, <StartPosition>] [, <NotFoundValue>] )
Parameter Attributes Description
FindText

The text you want to find. You can use the ? and * wildcard characters; use ~? and ~* to find the ? and * characters.

WithinText

The text in which you want to search for FindText.

StartPosition Optional

The character position in WithinText at which you want to start searching. If omitted, the default value is 1.

NotFoundValue Optional

The numeric value to be returned if the text is not found; if omitted, an error is returned.

Return values

Scalar A single integer value.

The number of the starting position of the first text string from the first character of the second text string.

Remarks

SEARCH supports wildcards, whereas FIND does not.

Examples

--  SEARCH searches the position of a substring inside a string.
--  Comparison is NOT case-sensitive.
--  You can provide the position from where to start searching
--  and a default value to return in case of no-match.
--  If no default value is provided, SEARCH raises an error in case 
--  the substring is not found.
EVALUATE
CALCULATETABLE (
    ADDCOLUMNS (
        TOPN ( 5, VALUES ( 'Product'[Product Name] ) ),
        "Position of red", SEARCH ( "red", 'Product'[Product Name], 1, BLANK () )
    ),
    'Product'[Color] IN { "Red", "Blue" }
)
Product Name Position of red
Contoso 512MB MP3 Player E51 Blue (Blank)
Contoso 2G MP3 Player E200 Red 28
Contoso 2G MP3 Player E200 Blue (Blank)
Contoso 4GB Flash MP3 Player E401 Blue (Blank)
Contoso 8GB Super-Slim MP3/Video Player M800 Red 46
--  SEARCH supports wildcards: ? and * to match any character or any
--  sequence of characters.
EVALUATE
CALCULATETABLE (
    ADDCOLUMNS (
        TOPN ( 5, VALUES ( 'Product'[Product Name] ) ),
        "player*blue", SEARCH ( "player*blue", 'Product'[Product Name], 1, BLANK () )
    ),
    'Product'[Color] IN { "Red", "Blue" }
)
Product Name player*blue
Contoso 512MB MP3 Player E51 Blue 19
Contoso 2G MP3 Player E200 Red (Blank)
Contoso 2G MP3 Player E200 Blue 16
Contoso 4GB Flash MP3 Player E401 Blue 23
Contoso 8GB Super-Slim MP3/Video Player M800 Red (Blank)

Related articles

Learn more about SEARCH in the following articles:

Related functions

Other related functions are:

Last update: Mar 1, 2021   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

MSDN documentation: https://docs.microsoft.com/en-us/dax/search-function-dax

2018-2021 © SQLBI. All rights are reserved. Information coming from MSDN is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of SEARCH? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.