RIGHT
Returns the last characters of a text value.
RIGHT(<text>, <num_chars>)Returns: Text (a scalar).
What it does
RIGHT returns the number of characters you ask for, counting from the end of the text. It is the way to read a suffix, such as the last four digits of a bank account, a check digit at the end of a code or the final part of a reference. The result is text.
Syntax and arguments
- text: the value to read from, a column or a text value.
- num_chars: how many characters to take from the right.
Example
The AP team shows the last four digits of a vendor's bank account on the payment review screen, so the approver can confirm it without seeing the full number.
Account Ending = "ending " & RIGHT(Vendors[BankAccount], 4)
A bank account of 1234567890 displays as "ending 7890". Show only the masked form on screens that many people can see, and keep the full number in a restricted table.
Example: a second, different use
Pick the file type from a document name, such as "invoice-0142.pdf", by reading the last three characters:
File Type = RIGHT(Documents[FileName], 3)
The result is "pdf". A filter on this column then separates PDFs from spreadsheets in a document inventory.
Things to watch
- RIGHT returns text, even for digits. Convert to a number with VALUE only when you do math on it.
- Trailing spaces count as characters, so TRIM the text first when the source is an export.
- If the text is shorter than num_chars, RIGHT returns the whole text.
- Masking with RIGHT is a display choice, not security. The full value is still in the model.
- For text whose suffix is not a fixed length, use SEARCH and MID.
In business terms
RIGHT is used to show partial account numbers for review, to read file extensions and to split a reference that carries a suffix such as a version number or a check digit. In controls work it supports the rule that sensitive data is displayed only in masked form.