/    /  Amazon QuickSight – Left

Amazon QuickSight – Left

 

In Amazon QuickSight left is a function that extracts a specified number of characters from the beginning of a string. The function takes two parameters: expression, which is the string to be evaluated, and limit, which is the number of characters to extract.

Syntax

#Start#
left(expression, limit)
#End#

 

This function takes two arguments

 

  • Expression: This is the string to be evaluated.
  • limit : This is the number of characters to extract

 

 

For example, let’s say we have a QuickSight dataset with a field called “Name” that contains full names, and we want to create a calculated field that includes only the first name. The left() function can extract the first name from the “Name” field. The following expression returns the first name from the “Name” field:

Example

#Start#
left({Name}, indexof({Name}, " ") - 1)
#End#

 

In this example, {Name} is a reference to the “Name” field in the dataset. The indexof() function is used to find the position of the first space character in the “Name” field, and the -1 is used to exclude the space character from the extracted string. The left() function then extracts the specified number of characters from the beginning of the “Name” field.

 

Note that if the “Name” field does not contain a space character, this expression will return the entire “Name” field. To handle this case, you can add a check to see if the indexof() function returns a value greater than zero. For example:

Example

#Start#
ifelse(indexof({Name}, " ") > 0, left({Name}, indexof({Name}, " ") - 1), {Name})
#End#

 

In this example, the ifelse() function checks if the indexof() function returns a value greater than zero. If it does, the left() function is used to extract the first name; otherwise, the entire “Name” field is returned.