Skip to main content

DAX RIGHT Function

The DAX RIGHT function in Power BI is used to extract a specified number of characters from the end of a text string. This function is particularly useful for retrieving suffixes, codes, or the last few characters of text fields, making it a vital tool for text manipulation and data preparation.


Syntax:

RIGHT(<text>, <num_chars>)

<text>: The text string from which you want to extract characters. <num_chars>: The number of characters to extract from the end of the text string.


Purpose:

The RIGHT function helps you isolate and work with the trailing portion of text data. This can be essential for tasks like extracting specific codes, file extensions, or other standardized suffixes from text fields.


Example:

Suppose you have a table named "Products" with a column "ProductCode" that contains alphanumeric codes, and you want to extract the last three characters of each product code.

You can use the RIGHT function as follows:

Suffix = RIGHT(Products[ProductCode], 3)


Example Scenario:

Assume you have the following "Products" table:



Using the RIGHT function, you can extract the last three characters of each product code:
Suffix = RIGHT(Products[ProductCode], 3)
The resulting table would be:



Combining with Other Functions:
You can combine the RIGHT function with other DAX text functions to create more complex text manipulations.
Example with LEFT and RIGHT:
To extract the first three and last three characters of a product code:
FirstThree = LEFT(Products[ProductCode], 3) LastThree = RIGHT(Products[ProductCode], 3)



Example with LEN and RIGHT:

To extract all but the first character of a product code:

AllButFirst = RIGHT(Products[ProductCode], LEN(Products[ProductCode]) - 1)



Related Functions:
LEFT: Returns the specified number of characters from the start of a text string.
MID: Returns a specific number of characters from a text string, starting at the position you specify.
LEN: Returns the number of characters in a text string.
CONCATENATE: Joins two text strings into one.
TRIM: Removes all spaces from a text string except for single spaces between words.
UPPER: Converts a text string to all uppercase letters.
LOWER: Converts a text string to all lowercase letters.

The RIGHT function in Power BI is a powerful tool for extracting specific parts of text strings from the end. Understanding how to use the RIGHT function effectively allows you to perform precise text manipulations

Comments