<!-- https://learnsql.cpetoday.com/functions/dax/search -->
# SEARCH

Language: DAX
Category: Text
Syntax: SEARCH(<find_text>, <within_text> [, <from_position>] [, <not_found_value>])
Summary: Returns the position of one text value inside another, ignoring case.
Returns: A whole number (a scalar). An error, or the not found value, when the text is absent.
Level: Intermediate
Related: FIND, MID, LEFT, RIGHT, ISNUMBER, LEN

## What it does
SEARCH tells you where a piece of text sits inside another piece of text, and returns its position, counting from 1. It ignores case, so "reversal" and "REVERSAL" are the same. The most common use is a test: wrap SEARCH in ISNUMBER to ask "does this text contain that word?" Use it to flag journal memos, bank descriptions or invoice notes that mention a keyword.

## Syntax and arguments
- find_text: the text to look for.
- within_text: the text to search in.
- from_position (optional): the position to start searching from. The default is 1.
- not_found_value (optional): what to return when the text is absent. Without it, a missing text causes an error, so supply one in most cases.

## Example
The controller wants to list the journal lines whose memo mentions a reversal, because reversals should be reviewed at close.

```dax
Is Reversal =
IF(
    ISNUMBER(SEARCH("reversal", Journal[Memo])),
    1,
    0
)
```

SEARCH finds "reversal" whatever the case in the memo. If the word is present the position is a number, ISNUMBER returns TRUE, and the line is flagged. Lines without the word get 0.

## Example: a second, different use
Find where the first hyphen sits in a reference, so the text before it can be taken with LEFT:

```dax
Hyphen Position = SEARCH("-", Invoices[Reference], 1, 0)
```

The not found value is 0, so a reference with no hyphen returns 0 rather than an error. Pair the position with LEFT to take the part before it.

## Things to watch
- SEARCH ignores case. Use FIND when the case matters.
- Without a not found value, a missing text returns an error. Use ISNUMBER(SEARCH(...)) to test for presence in a safe way.
- The position is counted from 1 for the first character. A zero is not a position.
- SEARCH is a text function, not a filter. For filtering, build a flag column with ISNUMBER(SEARCH(...)) and filter on that flag.
- Searching long memos for many words in a large table is slow. Build a flag column once and filter on it.

## In business terms
SEARCH finds the journal lines, bank descriptions and invoice notes that need attention: reversals, write-offs, manual adjustments, duplicate payments. The flags become the review list for a close or an internal audit sample.
