When working with data in Tableau, fields can have different data types, such as strings, numbers, dates, or Booleans. Sometimes the format of a field isn’t quite what you need for your analysis. This is where type conversion functions become useful.
Type conversion functions allow you to change a field from one data type to another so that it can be used correctly in calculations, filters, or visualisations.
When Would You Use Type Conversion?
Type conversion is useful in several real-world situations:
- Converting text numbers into numeric fields for calculations
- Turning numeric IDs into strings for labelling or concatenation
- Creating proper date fields from separate year, month, and day columns
Using the correct data type ensures calculations behave as expected and can also improve performance and clarity in your analysis.
Below are the most common type conversion functions in Tableau.
INT()
INT([Sales])
- Converts a value into an integer (a whole number)
- This function truncates decimal values rather than rounding them. For example,
INT(4.8)becomes4. - This can be useful when you need whole numbers for indexing, ranking, or binning calculations.
FLOAT()
FLOAT([Quantity])
- Converts a value into a floating-point number (a number that includes decimals).
- This is helpful when numeric values have been stored as strings and need to be treated as numbers in calculations.
STR()
STR([Order ID])
- Converts a value into a string (text).
- This is commonly used when combining fields in labels or tooltips, or when you need to concatenate numbers with text.
DATE()
DATE([Order Date])
- Converts a value into a date data type.
- This function is helpful when a date has been imported as a string or datetime and you only want the date portion.
DATETIME()
DATETIME([Timestamp])
- Converts a value into a datetime field, which includes both the date and time.
- This is useful when you need to work with time-level granularity, such as analysing events throughout the day.
MAKEDATE()
MAKEDATE([Year], [Month], [Day])
- Constructs a date from separate numeric components.
- This is particularly useful when datasets store dates in separate columns rather than a single date field.
In short, type conversion functions help ensure that fields are stored in the most appropriate format for analysis, making calculations more reliable and visualisations easier to build.
