Amazon QuickSight – Rtrim
The ‘rtrim’ function in Amazon QuickSight removes all trailing spaces from the right side of a string expression.
Syntax
#Start# rtrim(expression) #End#
This function takes one argument:
- expression (required): the string expression to remove trailing spaces from.
Suppose you have a dataset containing a field with strings that have trailing spaces that you want to remove.
Assume the following dataset:
| Item | Description |
| Apple | Fresh apples |
| Banana | Ripe bananas |
| Orange | Sweet oranges |
| Pear | Juicy pears |
| Peach | Delicious peaches |
| Mango | Juicy mangoes |
| Kiwi | Tangy kiwis |
To remove the trailing spaces from the Description field, you can use the rtrim function:
- Select the dataset that you want to create a calculated field for.
- Click on the “Add field” button.
- Enter the following expression:
Example
#Start# rtrim({Description}) #End#
This expression removes all trailing spaces from the Description field. The resulting calculated field will contain the trimmed strings.
- Click “Create field” to create the calculated field.
After creating this calculated field, you can use the trimmed strings for visualizations and analysis. In this example, the calculated field would have the following values:
| Item | Description | Trimmed Description |
| Apple | Fresh apples | Fresh apples |
| Banana | Ripe bananas | Ripe bananas |
| Orange | Sweet oranges | Sweet oranges |
| Pear | Juicy pears | Juicy pears |
| Peach | Delicious peaches | Delicious peaches |
| Mango | Juicy mangoes | Juicy mangoes |
| Kiwi | Tangy kiwis | Tangy kiwis |
Note that the “Trimmed Description” column is a calculated field, and the values are not stored in the original dataset.