Dax Function: RIGHT
Category: Text Functions
The RIGHT function in Power BI is a DAX (Data Analysis Expressions) function that extracts a specified number of characters from the end (right side) of a text string. It is commonly used in text manipulation and formatting tasks.
Purpose
- Text Extraction: Extract a specific portion of a text string starting from the rightmost character.
- Data Transformation: Prepare text data for analysis by isolating meaningful substrings.
- Formatting Adjustments: Extract parts of identifiers, codes, or fixed-width data.
Type of Calculations
The RIGHT function performs scalar text operations by slicing characters from the end of the input string.
Practical Use Cases
- Extracting Codes: Retrieve suffixes from alphanumeric strings like “Order123” to get “123.”
- Formatting Phone Numbers: Isolate the last few digits of phone numbers for display or analysis.
- Parsing Fixed-Width Data: Extract predefined-length segments from formatted text.
RIGHT(<text>, <num_chars>)</num_chars></text>
| Parameter | Type | Description |
|---|---|---|
| text | Text/Column | The text string from which characters are to be extracted. |
| num_chars | Integer | The number of characters to extract, starting from the rightmost character. |
How Does RIGTH Dax Function Works
- The RIGHT function operates by counting
num_charsfrom the end of the string. - It returns the substring starting from the calculated position to the end of the string.
- If
num_charsis zero, it returns an empty string.
What Does It Return?
The function returns a text string containing the specified number of characters from the end of the input text. If num_chars exceeds the length of the text, the entire string is returned.
When Should We Use It?
- String Parsing: To isolate suffixes, version numbers, or other trailing components in strings.
- Data Preparation: For cleaning and standardizing text fields in a dataset.
- Analysis and Reporting: To extract specific segments for reporting or display.
Examples
Basic Usage – Extract Suffix:
RIGHT("PowerBI", 3)
Result: "BI"
Column Usage – Extract Last Digits:
LastDigits = RIGHT(Employees[PhoneNumber], 4)
Retrieves the last four digits of phone numbers in the PhoneNumber column.
Advanced Usage – Combine with FIND:
Domain = RIGHT(Emails[Email], LEN(Emails[Email]) - FIND("@", Emails[Email]))
Extracts the domain name from an email address.
Tips and Tricks
- Ensure
num_charsdoes not exceed the length of the string to avoid unexpected results. - Combine with functions like LEN, FIND, or SEARCH for dynamic substring calculations.
- Use in conjunction with LEFT or MID for complex text extraction needs.
Performance Impact of RIGHT DAX Function:
- Optimized for single-column or scalar text processing.
- Avoid excessive use in calculated columns for large datasets to maintain performance.
Related Functions You Might Need
- LEFT: Extracts characters from the beginning of a text string.
- MID: Extracts a substring from a specified position within a text string.
- LEN: Determines the total number of characters in a text string.
Want to Learn More?
For more information, check out the official Microsoft documentation for RIGHT You can also experiment with this function in your Power BI reports to explore its capabilities.
Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.
The RIGHT function extracts a specified number of characters from the end of a text string.
Yes, you can calculate the num_chars dynamically using other DAX functions like LEN.
The entire text string is returned.
Yes, the function preserves the case of the characters in the text string.
Numeric values must first be converted to text using FORMAT or a similar function.