Monday, June 19, 2023

Explain the String Function ' LEFT ' in Tableau with Example?

 In Tableau, the "LEFT" function is used to extract a specified number of characters from the beginning (left) of a string. It returns a new string that contains the leftmost characters from the original string.


The syntax for the LEFT function in Tableau is as follows:


LEFT(string, length)


Here, "string" is the original string from which you want to extract characters, and "length" is the number of characters you want to extract from the left side of the string.


Let's consider an example to understand the usage of the LEFT function:


Suppose we have a dataset of product codes, and we want to extract the first three characters from each code to identify the product category. We can use the LEFT function to achieve this.


  • Create a calculated field by right-clicking on a blank area in the "Data" pane and selecting "Create Calculated Field."
  • In the calculation editor, enter the following formula:

            LEFT([Product Code], 3)

            Here, [Product Code] is the field containing the product codes, and we want to extract the first                 three characters from each code.


  • Provide a name for the calculated field, such as "ProductCategory," and click on the "OK" button.
  • You can now use the "ProductCategory" field in your analysis. You can display it in a table, use it in other calculations, or apply filters.


The LEFT function will extract the first three characters from each product code, giving you the product category.


For example, if the original product code is "ABC123", the LEFT function will return "ABC" by extracting the leftmost three characters.


By using the LEFT function in Tableau, you can manipulate and extract specific parts of strings to create new fields or perform further analysis based on the extracted information.

No comments:

Post a Comment

If you have any doubts. Please let me know

How can you create an alias for a table in a SQL query?

In SQL, you can create an alias for a table in a query to give the table a temporary, alternative name that you can use in the query. Table ...