Tableau Number to String: Easy Conversion Guide
In this article
To convert a number to a string in Tableau, use the STR() function. For example, STR([Sales]) returns the numeric field as text. You can also use STR(ROUND([Sales], 2)) to control decimals before conversion. This is useful when you need to concatenate numbers with text, display leading zeros, or format values for labels. No special setup is required beyond a Tableau workbook with a numeric field.
What You'll Need
- Tableau Desktop or Tableau Public (any recent version).
- A workbook with at least one numeric field (measure or dimension).
- Basic familiarity with calculated fields (right-click a field > Create > Calculated Field).
Step-by-Step
- Open your workbook and connect to your data source. Ensure the field you want to convert is numeric (its data type icon shows a number, like #).
- Create a calculated field. Right-click in the Data pane (or use the Analysis menu) and choose Create Calculated Field. Give it a name, e.g., Sales as Text.
- Write the STR() expression. In the formula box, type
STR([Sales])(replace [Sales] with your field). Click OK. The new field appears in the Data pane with an Abc icon, indicating a string. - Use the string field. Drag it to a worksheet (Rows, Columns, Label, etc.). You can now concatenate it with other strings using the
+operator, e.g.,"Total: " + STR([Sales]). - Control formatting (optional). STR() does not format numbers with thousands separators or fixed decimals. To round first, nest ROUND:
STR(ROUND([Sales], 2)). For leading zeros or custom patterns, use additional string functions likeRIGHT()orIFlogic. - Verify the result. Place the calculated field on a view and check that values appear as text (left-aligned by default). If you see numbers still right-aligned, the field may still be numeric—check the data type in the Data pane.
Note: Menu labels can differ slightly by version, device, or region. The steps above are for Tableau Desktop; Tableau Public is similar.
Common Mistakes
- Forgetting to round before STR(). STR() on a floating-point number may produce many decimal places. Always round or format first if you need clean output.
- Assuming STR() adds formatting. STR() does not add commas, currency symbols, or fixed decimal places. Use ROUND and string concatenation for that.
- Using STR() on a field that is already a string. This returns NULL. Check the data type first.
- Expecting STR() to handle dates. For dates, use only if the date is already a string; otherwise use DATENAME or FORMAT functions (availability varies).
- Mixing data types in calculations. Tableau requires explicit conversion when concatenating numbers with strings; STR() provides that.
Tips
- Use to drop decimals entirely.
- To pad with leading zeros, combine with for a 3-digit code.
- For dynamic formatting (e.g., thousands separators), consider creating a custom format string in the number format settings instead of converting to string, unless you specifically need text for concatenation.
- When building labels, you can often avoid STR() by using the Label shelf's multiple fields; but STR() gives more control over the exact text.
Troubleshooting
- STR() returns NULL. The input field is likely not numeric or contains nulls. Check the field's data type and handle nulls with
IFNULL([Field], 0)before converting. - Unexpected decimal places. Use
ROUND([Field], n)inside STR(). For example,STR(ROUND([Sales], 2))gives two decimals. - The calculated field shows as a measure, not a dimension. After creation, right-click the field in the Data pane and choose Convert to Dimension if you need it as a category.
- Concatenation fails with a type error. Ensure all parts are strings. Wrap numbers in STR() and use
+between strings. - Numbers appear in scientific notation. This can happen with very large or small numbers. Round first or use
FORMATif available in your version.
Frequently Asked Questions
Can I convert a number to a string without STR()?
You can use in some versions, but STR() is the most reliable and widely supported function. For simple concatenation, STR() is standard.
Does STR() work on aggregated fields?
Yes, but you must aggregate first: STR(SUM([Sales])). Otherwise, you may get an error about mixing aggregate and non-aggregate.
How do I keep leading zeros when converting?
STR() does not preserve leading zeros because it treats the number as numeric. Use string manipulation: for a 3-digit code.
Why does my STR() output show as a number in the view?
The field may still be treated as numeric if the calculation returns a number. Ensure the calculated field's data type is string (Abc icon). If not, edit the calculation to return a string, e.g., by concatenating with an empty string: .
Can I convert a string back to a number?
Yes, use INT() or FLOAT(). For example, INT([StringField]) converts a string of digits to an integer.
Does STR() work in Tableau Public?
Yes, STR() is available in all Tableau products, including Public and Desktop.