Amazon QuickSight – trim
The ‘trim()’ function in Amazon QuickSight is used to remove whitespace characters (space, tab, and newline) from the beginning and end of a string expression. Here is an explanation of the trim() function:
Syntax
#Start# trim(expression) #End#
This function takes one argument:
- expression: This is the string expression that is to be trimmed.
Suppose we have a dataset that contains information about employees’ names and their email addresses. We can use the trim() function in Amazon QuickSight to remove any leading or trailing spaces from the email addresses.
To remove the leading and trailing spaces from the email addresses, we can create a new calculated field in Amazon QuickSight with the following expression:
Example
#Start# trim(email_address) #End#
This expression will remove any leading or trailing spaces from the email addresses in our dataset.
For instance, if our email address data is as follows:
| Name | Email Address |
| John Doe | john.doe@example.com |
| Jane Smith | jane.smith@example.com |
| Bob Johnson | bob.johnson@example.com |
| Sally Lee | sally.lee@example.com |
| Jim Brown | jim.brown@example.com |
Then, the email address data with leading and trailing spaces removed will be:
| Name | Email Address | Email Address (trim) |
| John Doe | john.doe@example.com | john.doe@example.com |
| Jane Smith | jane.smith@example.com | jane.smith@example.com |
| Bob Johnson | bob.johnson@example.com | bob.johnson@example.com |
| Sally Lee | sally.lee@example.com | sally.lee@example.com |
| Jim Brown | jim.brown@example.com | jim.brown@example.com |
In this example, we can see that the trim() function has removed any leading or trailing spaces from the email addresses, resulting in a cleaner and more consistent dataset.