Text.BeforeDelimiter
What comes before a delimiter in a text: before its first occurrence, or before the one you choose.
Group: Text and characters. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Text.BeforeDelimiter(text as nullable text, delimiter as text, optional index as any) as any
| Parameter | Type | Description |
|---|---|---|
text | nullable text | The text to work on; null gives null. |
delimiter | text | The text to look for. |
index | any optional | Which occurrence of the delimiter to use, counted from 0; or a list {index, RelativePosition.FromEnd} to count from the end of the text. Left out, the first one. |
Returns
any. The text up to the delimiter; the whole text when the delimiter isn't there.
Remarks
- The search is exact: case counts.
Examples
The country code
Text.BeforeDelimiter("NO-0150-Oslo", "-")
"NO"
Up to the last dash
Text.BeforeDelimiter("NO-0150-Oslo", "-", {0, RelativePosition.FromEnd})
"NO-0150"
No delimiter in the text
Text.BeforeDelimiter("NO-0150-Oslo", "/")
"NO-0150-Oslo"
The whole text comes back.
Related functions
Text.AfterDelimiter, Text.BetweenDelimiters, Text.Start, Text.Split.