Calculated Field - Type Conversions

Type Conversions are used to convert fields from one data type to another.

Here is a list of the most common type conversions, what they do and how to use them:

STR -

If you do not want Tableau to aggregate your data, then you may wish to convert the data type to a string.

The STR function takes any data type and converts it to a string.

Data Type - Input vs Output

The Syntax for this would be:  STR (expression)

Example:

FLOAT -

A float function will take any numeric data type  and convert it to a floating decimal.

The syntax for a FLOAT function is: FLOAT (expression)

INT -

This function will take any number and truncate it to a decimal. This means that any values after the decimal place will be ignored.

The INT function will take numeric or string values and return an integer value.

The syntax for this function is : INT (expression)

Examples:

DATE -

Converts strings, numbers or date expressions into a date data type.

The input should be something that Tableau recognises as a date. If Tableau does not automatically identify the date format, you may want to use the DateParse function (see Date Calculations of Tableau for more information) to specify a format. Null values could be an indicator of Tableau not recognising the date format.

The Syntax for this function is Date(expression), however quotation marks may be needed if inputting data directly rather than using a field:

Examples:

Currently, Tableau can identify these date formats automatically:

Screenshot from https://help.tableau.com

DATETIME

Very similar to the DATE function, but instead of converting to a Date data format, it makes it a DateTime.

If your input is a date, the time will automatically set to 00:00:00 (midnight).

Examples:

MAKEDATE -

Can be used with numeric values only.

Syntax: MAKEDATE ( year, month, day)

Example:

Check out Muhammad Choudhury's blog to find out more about date calculations.

Author:
Amelia Holland
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab