<!-- https://learnsql.cpetoday.com/functions/dax/left -->
# LEFT

Language: DAX
Category: Text
Syntax: LEFT(<text>, <num_chars>)
Summary: Returns the first characters of a text value.
Returns: Text (a scalar).
Level: Beginner
Related: RIGHT, MID, LEN, SEARCH, FIND, SUBSTITUTE

## What it does
LEFT returns the number of characters you ask for, counting from the start of the text. It is the simplest way to pull a prefix out of a code, such as the first digit of an account number that tells you whether it is an asset, a liability, equity, revenue or expense. The result is text, even when the characters look like a number.

## Syntax and arguments
- text: the value to read from, a column or a text value.
- num_chars: how many characters to take from the left. Use 1 for one character.

## Example
Many charts of accounts use the first digit to group the accounts: 1 for assets, 2 for liabilities, 4 for revenue and 5 for expenses. The model needs an account class column for a summary.

```dax
Account Class =
SWITCH(
    LEFT(GL[AccountNumber], 1),
    "1", "Assets",
    "2", "Liabilities",
    "3", "Equity",
    "4", "Revenue",
    "5", "Expenses",
    "Other"
)
```

LEFT returns a text digit, so the comparisons use quoted text. Writing 4 without quotes would compare a number with text, which is a common error.

## Example: a second, different use
Group invoice numbers by their year prefix, such as "2026-00142" starts with the year:

```dax
Invoice Year = LEFT(Invoices[InvoiceNumber], 4)
```

The year is text. If you need a number to filter or sort, wrap it in VALUE.

## Things to watch
- LEFT returns text. Compare with quoted text, not a number.
- If the text is shorter than num_chars, LEFT returns the whole text.
- LEFT counts characters, not bytes or words. Leading spaces count, so clean the text with TRIM when the source is messy.
- A code split with LEFT is brittle. If the format changes, the prefix may point to the wrong group.
- LEFT and RIGHT are good for fixed-format codes. For variable-length text, use SEARCH and MID.

## In business terms
LEFT is used to read chart of accounts classes, fiscal year prefixes on document numbers, region codes and product families from a code. Finance teams use it to group a mapping table before the group is used for a consolidation or a statutory return.
