<!-- https://learnsql.cpetoday.com/functions/m/text-beforedelimiter -->
# Text.BeforeDelimiter

Language: Power Query M
Category: Text
Syntax: Text.BeforeDelimiter(text as nullable text, delimiter as text, optional index as any) as nullable text
Summary: Returns the part of a text value that comes before a delimiter.
Returns: The text before the first delimiter (or the chosen one), or null when the input is null.
Level: Beginner
Related: Text.AfterDelimiter, Text.BetweenDelimiters, Text.Split, Text.Start, Text.Trim

## What it does
Many finance labels are a code and a name joined by a separator: "1000-Cash", "V0042 | Acme Supply", "Dallas, TX". Text.BeforeDelimiter keeps the code and drops the rest. It finds the first occurrence of the delimiter by default, and returns the text before it.
## Syntax and arguments
- text: the value to read from.
- delimiter: the text that marks the split. It is matched exactly.
- index (optional): chooses which occurrence of the delimiter to use. Leave it out for the first one.
## Example
A chart of accounts export has each account as "1000-Cash". The team needs the number on its own to join to the account master.

```powerquery
let
    Accounts = #table(type table [Label = text],
        {{"1000-Cash"}, {"2100-Accounts payable"}, {"4010-Product sales"}}),
    WithCode = Table.AddColumn(Accounts, "Account", each Text.BeforeDelimiter([Label], "-"), type text)
in
    WithCode
```

The Account column holds "1000", "2100" and "4010". Those are text, so they will join to the master list as long as the master is also text.
## Example: a second, different use
Keep the vendor name from a label such as "Acme Supply Co, Dallas TX" by taking the text before the comma.
## Things to watch
- The default is the first delimiter. A value with two dashes splits at the first one, so check labels that contain the separator in the name.
- The result is text. A code such as "1000" stays text, and joins must match type.
- If the delimiter is not in the value, the result may be null rather than the whole value. Check labels with no separator before you rely on the split.
- Null in gives null out.
## In business terms
Account labels, cost centers and vendor codes are often combined into one field in exports. Splitting out the code is how the chart of accounts and the vendor master join to the transactions in a clean, repeatable way.
