If you want to pull out the part of a text value that comes after a specific character, like the domain after the @ in an email or the extension after the dot in a file name, the Text.AfterDelimiter function is what you reach for.
It returns everything that sits to the right of the delimiter you name. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.
Syntax of Text.AfterDelimiter Function
Text.AfterDelimiter(text as nullable text, delimiter as text, optional index as any) as any
where
text(required, nullable text). The text value you want to pull a piece out of.delimiter(required, text). The character or string that marks the cut-off point. Everything after it is returned.index(optional, any). Which occurrence of the delimiter to use, counted as a 0-based number. It accepts two forms:- A plain number, like
0,1,2, which counts occurrences from the start.0(the default when omitted) is the first occurrence. - A list of the form
{relativeIndex,RelativePosition.FromStart}or{relativeIndex,RelativePosition.FromEnd}, which lets you count occurrences from the end instead.{0,RelativePosition.FromEnd}is the last occurrence.
- A plain number, like
Returns: a text value containing everything after the chosen delimiter. If the delimiter is not found, it returns an empty string "".
In plain terms, you give it a piece of text and a delimiter, and it hands back whatever comes after that delimiter.
Example 1: Get the text after the first delimiter
Pull everything after the first hyphen in an invoice code.
let
Source = Text.AfterDelimiter("invoice-2024-Q3","-")
in
Source
Result: 2024-Q3
With no index given, it stops at the first hyphen and returns the rest of the string, hyphens included.
Example 2: Get the text after the second delimiter
Use the index argument to count past the first occurrence. Here you want everything after the second hyphen.
let
Source = Text.AfterDelimiter("2024-03-15-report","-",1)
in
Source
Result: 15-report
The index is 0-based, so 1 points at the second hyphen, and the function returns whatever follows it.
Example 3: Get the file extension with FromEnd
To grab a file extension, you want the text after the last dot, not the first. Count from the end with a {0,RelativePosition.FromEnd} list.
let
Source = Text.AfterDelimiter("annual-budget-final.xlsx",".",{0,RelativePosition.FromEnd})
in
Source
Result: xlsx
{0,RelativePosition.FromEnd} means the first dot counting from the right, which is the last dot in the string.
Example 4: Get the domain from an email address
Split an email on the @ to keep just the domain part.
let
Source = Text.AfterDelimiter("sumit@spreadsheetplanet.com","@")
in
Source
Result: spreadsheetplanet.com
There is only one @, so the default first-occurrence behavior returns everything after it.
Example 5: Get the last segment of a path
Pull the final segment out of a slash-separated path by counting the last slash from the end.
let
Source = Text.AfterDelimiter("/sales/2024/east/totals","/",{0,RelativePosition.FromEnd})
in
Source
Result: totals
Counting from the end means you do not have to know how many slashes the path has. The last one always gives you the trailing segment.
Example 6: What happens when the delimiter is not found
If the delimiter never appears in the text, the function returns an empty string.
let
Source = Text.AfterDelimiter("no_delimiter_here","-")
in
Source
Result: "" (empty text)
There is no hyphen in the input, so there is nothing “after” it to return, and you get an empty string "" rather than the original text.
Things to keep in mind with Text.AfterDelimiter
- It is the mirror image of
Text.BeforeDelimiter, but the two behave differently when the delimiter is missing.Text.AfterDelimiterreturns"", whileText.BeforeDelimiterreturns the whole input string. That catches people off guard, so test for the delimiter first with Text.Contains if your data is mixed. - The delimiter is case-sensitive. Searching for
"x"will not match an uppercase"X". Normalize the case first withText.LowerorText.Upperif needed. - For splitting one column into many, reach for a different tool.
Text.AfterDelimiterreturns a single piece. To break a column into several columns at once, useTable.SplitColumnwithSplitter.SplitTextByDelimiterinstead of chaining this function.
Common questions about Text.AfterDelimiter
What is the difference between Text.AfterDelimiter and Text.BeforeDelimiter?
Text.AfterDelimiter returns the text to the right of the delimiter, while Text.BeforeDelimiter returns the text to the left. They also differ when the delimiter is missing: the “after” version returns an empty string, but the “before” version returns the whole input.
How do I get the text after the LAST occurrence of a delimiter?
Pass a {0,RelativePosition.FromEnd} list as the index, like Text.AfterDelimiter([Path],"/",{0,RelativePosition.FromEnd}). This counts the first delimiter from the end, which is the last one in the string.
How do I get the text between two delimiters?
Combine both functions. Take the text after the opening delimiter with Text.AfterDelimiter, then wrap that in Text.BeforeDelimiter to cut at the closing delimiter, leaving only the middle piece.
List of All Power Query Functions
Related Power Query Functions / Articles:
- Text.BeforeDelimiter Function
- Text.BetweenDelimiters Function
- Text.StartsWith Function
- Text.Split Function
- Text.PositionOf Function
- Text.TrimEnd Function
- Text.Range Function
- Text.Middle Function
- Table.SplitColumn Function
- Text.Clean Function
- Splitter.SplitTextByDelimiter Function
- Text.TrimStart Function