The LEFT function extracts a number of characters from the beginning (from the left) of the text string passed as an argument.
LEFT(
text,
num_chars
)
- text: Text or name of the column that contains the text strings from which to extract the characters.
- num_chars: Number of characters to extract.
The LEFT function returns a text string.
If the num_chars argument is greater than the length of text, the function returns the original text (that is, the length of the value returned by the function is always limited by the length of the text string from which you want to extract the characters).
If num_chars is zero, LEFT returns an empty text string. This empty string is not interpreted as a Blank by the ISBLANK function. For example, the following table includes the Left 0 column in which 0 characters are extracted from the left of the content of the Manufacturer column, and the Es blank column checks whether the content of the Left 0 column is Blank or not:
If num_chars is a negative value, the function returns an error.
Although Microsoft Excel includes LEFT-equivalent functions designed to work with languages that use the one-byte character set (such as Spanish or English) and others to work with languages that use the two-byte character set (so-called DBCS -Double Byte Character Set-, including Japanese, Simplified and Traditional Chinese, and Korean) -LEFT and LEFTB functions, respectively-, DAX uses the UNICODE format and stores all characters with the same length, so a single version of the LEFT function is sufficient.
The following example extracts 3 characters from the left of the manufacturer's name to use as an identifier. Note how upper and lower case are respected:
In the following example, the first word is extracted from the Category column, word understood as a set of characters limited by a blank space. For this purpose, the SEARCH function is used to obtain the position of the first blank space starting from the left of the text and with the LEFT function the characters up to said blank space are extracted (note how one character is subtracted to extract only the characters before whitespace, that is, to not include the white space in the first word).
If no white space is found, the SEARCH function includes as a fourth argument the LEN function that returns the length of the text contained in Category (that is, if no white space is found, the first word is considered to be the entire text string). If this fourth argument were not included, the LEFT function would return an error caused by those text strings that do not include white spaces (and the error would be displayed in all the rows even if there are only some that do not include white spaces).
The Length column shows the length of the extracted word.