Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Tableau Calculated Field String: Step-by-Step Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To create a string calculated field in Tableau, open a worksheet, click Analysis > Create Calculated Field (or right-click in the Data pane and choose Create Calculated Field), give the field a name, and write an expression that returns text—for example LEFT([Customer Name], 5) or [First Name] + ' ' + [Last Name]. String calculated fields let you clean, combine, extract, or reformat text values so they display and filter the way you need. This guide walks through the exact steps, the functions you will actually use, and the mistakes that trip people up. The menu labels below can differ slightly by Tableau version, edition, or region, but the workflow is the same on Tableau Desktop and Tableau Public; Tableau Cloud and Server use the same calculation editor in the browser.

What You'll Need

  • Tableau Desktop, Tableau Public, or a Tableau Cloud/Server authoring session with permission to create calculated fields.
  • A data source already connected and at least one text (string) dimension or measure to work with.
  • A worksheet open—calculations can be created from the Data pane or the Analysis menu.
  • Basic familiarity with dragging fields onto Rows, Columns, or Marks.

Step-by-Step

  1. Open the calculation editor. In Tableau Desktop, click Analysis > Create Calculated Field. Alternatively, right-click any blank area of the Data pane and choose Create Calculated Field, or click the drop-down arrow at the top of the Data pane and select the same option. In Tableau Cloud or Server, the same command appears in the Analysis menu of the web authoring view.
  2. Name the field. Type a descriptive name in the top box, such as Customer Initials or Full Address. Avoid names that duplicate existing fields; Tableau will warn you if the name is already in use.
  3. Write a string expression. In the formula area, type an expression that returns text. Useful patterns:
    • Combine fields: [First Name] + ' ' + [Last Name]
    • Extract characters: LEFT([Order ID], 3) or RIGHT([Phone], 4)
    • Find text: FIND([Email], '@') returns the position of the @ sign.
    • Replace text:
    • Change case: or LOWER([Email])
    • Trim spaces:
    • Convert numbers to text: STR([Sales])
    • Conditional text: IF [Status] = 'Open' THEN 'Active' ELSE 'Closed' END
  4. Check for validity. Tableau underlines errors in red and shows a message below the formula box. A valid expression shows “The calculation is valid” in green. Fix any red underlines before continuing.
  5. Click OK. The new field appears in the Data pane under Measures or Dimensions, depending on whether the result is treated as a dimension or measure. String fields are usually dimensions.
  6. Use the field in the view. Drag it to Rows, Columns, Filters, or Label. You can also use it in other calculated fields, just like any other field.
  7. Test with sample rows. Right-click the new field in the Data pane and choose Edit to reopen the calculation. The preview table at the bottom of the editor shows sample values so you can confirm the output before closing.

Common Mistakes

  • Using double quotes for string literals. Tableau uses single quotes for text values. 'Active' is correct; "Active" will cause an error.
  • Forgetting the plus sign when joining text. In Tableau, + concatenates strings. Using & or a comma will not work.
  • Mixing data types. Adding a number directly to a string, such as , fails. Wrap the number with STR() first.
  • Assuming nulls behave like empty strings. A null field plus text often returns null. Use IFNULL([Field], '') or ZN() where appropriate.
  • Naming a field with spaces and then referencing it without brackets. Always wrap field names in square brackets, e.g. [Full Name].
  • Expecting string calculations to change the underlying data. Calculated fields are virtual; they do not edit the source. To persist changes, use a data preparation step or a physical extract.

Tips

  • Use the calculation editor’s function list (the drop-down on the right) to insert functions and see their syntax without guessing.
  • Press Enter inside the formula box to add line breaks and keep long expressions readable.
  • Comment your logic with // at the start of a line; Tableau ignores everything after it on that line.
  • If you need to split text on a delimiter, SPLIT([Field], '-', 1) returns the first part. The third argument is the token number, starting at 1.
  • For case-insensitive comparisons, use LOWER() on both sides rather than relying on the database collation.
  • Keep a naming convention such as calc_ or cf_ so calculated fields are easy to spot in the Data pane.

Troubleshooting

If the calculation will not validate, read the red message under the formula box—it usually names the exact problem, such as an unknown field or a type mismatch. Check that every field name is spelled exactly as it appears in the Data pane and wrapped in brackets. If the field exists but the editor says it cannot be found, confirm you are editing the calculation in the same data source as the field.

If the field validates but shows null or blank results in the view, inspect the sample data in the preview table. Nulls in the source often propagate through string functions; wrap the input with IFNULL() or filter out nulls. If only some rows are wrong, check for leading or trailing spaces using TRIM(), and confirm that the case matches any literal comparisons.

If the new field does not appear in the Data pane, make sure you clicked OK rather than Cancel, and that you are looking at the correct data source—Tableau lists calculated fields under the source they belong to. If the field appears but cannot be dragged into the view, it may be a measure that needs an aggregation; right-click it and choose Convert to Dimension if appropriate.

If the calculation worked yesterday and fails today, the underlying data or field names may have changed. Reopen the calculation, re-check the field references, and update any renamed columns. For published data sources, confirm you have permission to edit calculations; otherwise, save a local copy and adjust there.

Frequently Asked Questions

Can I use double quotes for text in Tableau calculations?

No. Tableau requires single quotes around string literals, for example 'Open'. Double quotes are reserved for other purposes and will produce a syntax error.

How do I combine two text fields into one?

Use the plus operator: [First Name] + ' ' + [Last Name]. Include a literal space in single quotes if you want a separator.

Why does my string calculation return null?

Most often one of the input fields is null. Wrap the input with IFNULL([Field], '') so nulls become empty text, or filter null rows out of the view.

Can I convert a number to text inside a calculation?

Yes. Use to turn a numeric value into a string, then concatenate it with other text.

Do calculated fields change the original data?

No. Calculated fields are virtual and exist only in the workbook or published data source. They do not modify the underlying database or file.

How do I extract the first few characters of a text field?

Use LEFT([Field], n), where n is the number of characters. For the last characters, use RIGHT([Field], n).