Amazon QuickSight – Strlen
The ‘strlen’ function in Amazon QuickSight returns the length of a specified string expression in characters.
Syntax
#Start# strlen(expression) #End#
This function takes one argument:
- expression (required): the string expression to measure the length of.
Suppose you have a dataset containing a field with email addresses, and you want to create a calculated field that returns the length of each email address.
Assume the following dataset:
| Name | Age | |
| John Smith | john.smith@example.com | 35 |
| Jane Doe | jane.doe@example.com | 28 |
| Bob Johnson | bob.johnson@example.com | 42 |
To create a calculated field that returns the length of each email address, you can use the strlen function:
- Click on the “Add calculated field” button in the analysis pane.
- Enter a name for the calculated field, such as “Email Length”.
- Enter the following expression for the calculated field:
Example
#Start# strlen({Email}) #End#
This expression returns the length of the email address in the current row.
- Click “Create” to create the calculated field.
After creating the calculated field, the dataset would include the following additional column:
| Name | Age | Email Length | |
| John Smith | john.smith@example.com | 35 | 19 |
| Jane Doe | jane.doe@example.com | 28 | 17 |
| Bob Johnson | bob.johnson@example.com | 42 | 20 |
The strlen function is useful for calculating the length of strings, which can be useful for various purposes such as data validation or formatting.