How to remove a special character from the name in Tableau?
If your data includes the symbols such as arrows, commas, dashes, or the hash, you might need to detach those characters from the text. It is necessary if you need to connect two or more databases with the same fields. Since changing data in the original sources can be labor-intensive, it can be done promptly in the table.
Below are two possible ways how to do that using a custom calculation.
1. Using the MID function if a character is at the beginning
For example, you may have a field that contains ‘Customer Name’ with some of the field members — I use a standard Superstore database in this case. As you can see, a customer name has a dash symbol at the beginning.
To remove the dash, we can use the MID function that returns the characters in a string starting at the index starting position.
STEP 1. Create a custom calculation with a function MID
The arguments will be a string, start, and length, which means — a dimension you want to change, the number of spaces you wish to delete, and the number of characters for your text to remain.
So, the function looks like this: MID([Customer Name],2,20)
STEP 2. Apply a new value in the rows field
Shifting the text by two characters allows removing unnecessary punctuation.
If you need to differentiate two dimensions you can use an extended formula
IF LEFT([customer namenew],1) = “1” THEN MID(customer name,3,25) ELSE([customer name]) END
2. Using REPLACE function if a character is in the middle
The function will replace part of a text string with a different text string based on the number of characters you specify.
In this example, we will consider a situation when there is an additional hashtag in the product id in your database. Let’s look at how to display this symbol with spare space.
STEP 1. Create a custom calculation REPLACE
The arguments will be your dimension, the current symbol you want to remove, and the replacement you want to see. Since we need nothing back, we leave the quotation marks with a blank space.
REPLACE(([Product ID],’#’,’’)
STEP 2. Add the calc to the rows
So the correct results are ready. These functions help you to clean the data directly in Tableau.