Text.Reverse
TextReturns a text value with the characters in reverse order.
Syntax
Text.Reverse(text as nullable text) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
text | text | Yes | The source text value to reverse. |
Return Value
text — The text value with characters reversed.
Remarks
Text.Reverse returns a new text value containing all the characters of text in reverse order. If text is null, the function returns null. An empty string returns an empty string unchanged.
This function operates on individual Unicode code units (16-bit values). For text containing surrogate pairs or combining character sequences (such as emoji composed of multiple code units, or diacritics applied to a base character), the result may not be linguistically meaningful. For ASCII and most Western European text, reversal works as expected.
In most production data transformation work, Text.Reverse is used for specific parsing patterns. A common technique is to extract the last occurrence of a variable-position delimiter: Text.Reverse the string, use Text.BeforeDelimiter on the first occurrence, then Text.Reverse the result again. This is equivalent to using Text.BeforeDelimiter with {0, RelativePosition.FromEnd} but may be easier to understand in some contexts.
Examples
Example 2: Check if a string is a palindrome
let
word = "racecar",
isPalindrome = (word = Text.Reverse(word))
in
isPalindromeThe final output — compares the original word to its reversed version using Text.Reverse; returns true because "racecar" reads the same forwards and backwards.
Result | |
|---|---|
| 1 | TRUE |
Example 3: Extract the last segment of a delimited string by reversing
let
path = "Sales/East/Q1/Alice",
lastSegment = Text.Reverse(Text.BeforeDelimiter(Text.Reverse(path), "/"))
in
lastSegmentThe final output — reverses the path to "ecilA/1Q/tsaE/selaS", extracts the text before the first "/" to get "ecilA", then reverses that result back to "Alice".
Result | |
|---|---|
| 1 | Alice |