Monday, June 19, 2023

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

 In Tableau, the "TRIM" function is used to remove leading and trailing spaces from a string. It returns a new string with any leading and trailing spaces removed.


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


TRIM(string)


Here, "string" is the original string from which you want to remove the spaces.

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


Suppose we have a dataset of employee names, and some of the names have leading or trailing spaces. We want to remove these spaces and standardize the names. We can use the TRIM function to accomplish 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:

                TRIM([Employee Name])

            Here, [Employee Name] is the field containing the employee names that may have leading or                   trailing spaces.


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


The TRIM function will remove any leading and trailing spaces from the employee names, resulting in standardized names without extra spaces.


For example, if the original name is " John Doe ", the TRIM function will return "John Doe" by removing the leading and trailing spaces.


By using the TRIM function in Tableau, you can clean up your data by eliminating unnecessary spaces from strings, ensuring consistency and accuracy in your analysis.

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 ...