Tableau String Functions: A How-To Guide
In this article
Tableau string functions let you clean, split, combine, and extract text directly in calculated fields, so you can fix messy data without leaving Tableau. To use them, open a calculated field (Analysis > Create Calculated Field), type an expression such as LEFT([Customer Name], 5) or SPLIT([Email], '@', 1), and drag the new field onto a shelf. The exact menu labels can differ slightly by Tableau version and platform, but the function names and behavior are consistent.
What You'll Need
- Tableau Desktop or Tableau Cloud/Public with a worksheet open and at least one text field in your data source.
- Basic familiarity with calculated fields (where to create them and how to drag them onto Rows, Columns, or Marks).
- A clear idea of the text pattern you want to extract or change, for example a full name, an email address, or a product code.
Step-by-Step
- Open a calculated field. In Tableau Desktop, go to Analysis > Create Calculated Field. In Tableau Cloud or Public, click the arrow next to the search bar or the data pane and choose Create Calculated Field. A dialog box opens where you name the field and write the expression.
- Start with a simple function to see how it behaves. For example, create a field called First 3 with . Click OK, then drag it onto Rows to preview the result. This confirms you are referencing the right field and that the output looks as expected before you build something more complex.
- Combine functions for real cleaning tasks. To trim spaces and change case, use . To replace a character, use REPLACE([Phone], '-', '') . To find a position, use FIND([Email], '@') . Each function takes specific arguments; check the function reference in Tableau's help if you are unsure of the order.
- Extract parts of a string. Use
LEFT,RIGHT, andMIDfor fixed positions, orSPLITfor delimited text. For example,SPLIT([Full Name], ' ', 1)returns the first word, andSPLIT([Full Name], ' ', 2)returns the second. If a value has fewer parts than you ask for, SPLIT returns an empty string, so test with a few rows. - Measure length and compare strings.
LEN([Description])gives character count, which is useful for flagging unusually short or long entries.CONTAINS([Notes], 'urgent')returns true or false, andSTARTSWITHorENDSWITHwork similarly for prefixes and suffixes. - Use string functions inside logic. Wrap them in IF or CASE to create categories. For example:
IF CONTAINS([Comment], 'refund') THEN 'Refund' ELSE 'Other' END. This lets you group text-based feedback without editing the source data. - Check results with a table. Drag the original field and your new calculated field onto Rows side by side. Scan for blanks, unexpected nulls, or truncated values. String functions return null when the input is null, so you may need
IFNULLorZN(for numbers) around them. - Name and save the field clearly. Give it a descriptive name like Clean Customer Name so others know what it does. Click OK to save. The field appears in the data pane under Measures or Dimensions depending on its output type; string outputs are dimensions.
Common Mistakes
- Forgetting that string functions are case-sensitive in some contexts. Tableau's string comparisons are generally case-sensitive. Use
LOWERorUPPERon both sides if you need case-insensitive matching. - Assuming SPLIT always returns a value. If the delimiter is missing or the requested part does not exist, SPLIT returns an empty string, not an error. Always preview with real data.
- Using the wrong argument order. For example,
MID(string, start, length)takes the start position first. Mixing up start and length produces odd results that can look like data errors. - Ignoring nulls. Many string functions return null if any input is null. Wrap with
IFNULL([Field], '')when you need a fallback. - Overcomplicating with nested functions. Build the expression in small pieces, test each piece, then combine. A single long formula is hard to debug.
Tips
- Use
TRIMbefore comparing or grouping; trailing spaces often cause mismatches. - For emails, extract the domain with
MID([Email], FIND([Email], '@') + 1)after confirming every row contains an @. - When splitting names, test with names that have middle initials or suffixes; SPLIT by space may not give you the last name reliably.
- Keep a copy of the original field on the worksheet while you build the calculated field, so you can compare side by side.
- Document complex formulas with a comment in the calculation editor (using //) so future you remembers the logic.
Troubleshooting
- The calculated field shows an error. Check parentheses and commas. Tableau highlights the problem area. Also confirm the field names match exactly, including spaces and brackets.
- Results are blank or null. The source value may be null or the function may be returning an empty string. Test with
ISNULL([Field])to identify null rows. - Unexpected characters appear. Hidden spaces or non-printing characters may be present. Use
TRIMandREPLACEto clean them, or check the source data. - The field does not appear where expected. String calculations produce dimensions, not measures. Look in the Dimensions area of the data pane.
- Performance slows with many string calculations. String functions run row by row; if the data source is large, consider cleaning in the data source or using extracts. For very complex parsing, a data preparation tool may be more efficient.
Frequently Asked Questions
Can I use string functions on a field that is not text?
No. String functions require a string input. Convert numbers or dates to strings first with STR(), but note that formatting may change.
What is the difference between LEFT and SPLIT?
LEFT returns a fixed number of characters from the start. SPLIT divides a string by a delimiter and returns the part at a given position. Use LEFT for fixed-width codes and SPLIT for delimited text.
Do string functions work in Tableau Public?
Yes, the same calculated field functions are available in Tableau Public, Cloud, and Desktop, though the interface for creating them may differ slightly.
How do I remove leading zeros from a text field?
If the field is text, use REPLACE([Field], '0', '') carefully, as it removes all zeros. A safer approach is to convert to a number with INT([Field]) if the values are numeric, then convert back to string if needed.
Why does my calculated field return an empty string instead of null?
Some functions like SPLIT return an empty string when the requested part does not exist. Check your delimiter and position arguments. Use IF [Field] = '' THEN 'missing' ELSE [Field] END to handle it.
Can I nest multiple string functions?
Yes, nesting is common, for example . Build and test each layer to avoid errors.