Type Conversion

This article introduces type conversion functions and their uses in Tableau. It also demonstrates how to create a type conversion calculation using an example.

Why use type conversion functions

Type conversion functions allow you to convert fields from one data type to another (this is called "casting"). For example, if you have date information in a field with a string data type, you won't be able to use that field in date calculations unless the field is cast (changed) to a date data type.

For example, to use a string date field in a DATEDIFF function, you'd also need to use a date type conversion:

DATEDIFF('day', [Date Field], DATE([String Date Field]) )

Without the DATE function changing the data type, you'd get an error that "DATEDIFF is being called with (string, date, string)".

A calculation error message showing a type conversion error

Tip: Fields have default Data Types in the Data pane. In many instances, you don't need to use a type conversion function at all. You can change the field's data type by clicking the icon. However, in some cases it can be useful to change the data type only for a specific calculation, or Tableau may not be able to correctly cast the field's contents to the desired data type (such as not recognising the date format). Then you would need to use a type conversion function like those listed below.

Type conversion functions available in Tableau

DATE

SyntaxDATE(expression)
OutputDate
DefinitionReturns a date, given a number, string or date expression.
Example
DATE([Employee Start Date])
DATE("September 22, 2018") 
DATE("9/22/2018")
DATE(#2018-09-22 14:52#)
Notes

Unlike DATEPARSE(Link opens in a new window), there is no need to provide a pattern as DATE automatically recognises many standard date formats. If DATE does not recognise the input, however, try using DATEPARSE and specifying the format.

MAKEDATE(Link opens in a new window) is another similar function, but MAKEDATE requires the input of numeric values for year, month and day.

DATETIME

SyntaxDATETIME(expression)
OutputDatetime
DefinitionReturns a datetime given a number, string or date expression.
Example
DATETIME("April 15, 2005 07:59:00") = April 15, 2005 07:59:00

FLOAT

SyntaxFLOAT(expression)
OutputFloating point number (decimal)
DefinitionCasts its argument as a floating point number.
Example
FLOAT(3) = 3.000
NotesSee also INT, which returns an integer.

INT

SyntaxINT(expression)
OutputInteger
DefinitionCasts its argument as an integer. For expressions, this function truncates results to the closest integer toward zero.
Example
INT(8/3) = 2
INT(-9.7) = -9
Notes

When a string is converted to an integer it is first converted to a float and then rounded.

See also FLOAT, which returns a decimal.
See also ROUND(Link opens in a new window), CEILING(Link opens in a new window) and FLOOR(Link opens in a new window)

MAKEDATE

SyntaxMAKEDATE(year, month, day)
OutputDate
DefinitionReturns a date value constructed from the specified numerical year, month and date.
Example
MAKEDATE(1986,3,25) = #1986-03-25#

Note that incorrectly entered values will be adjusted into a date, such as MAKEDATE(2020,4,31) = May 1, 2020 rather than returning an error that there is no 31st day of April.

Notes

Available for Tableau Data Extracts. Check for availability in other data sources.

MAKEDATE requires numerical inputs for the parts of a date. If your data is a string that should be a date, try the DATE function. DATE automatically recognises many standard date formats. If DATE does not recognise the input try using DATEPARSE.

MAKEDATETIME

SyntaxMAKEDATETIME(date, time)
OutputDatetime
DefinitionReturns a datetime that combines a date and a time. The date can be a date, datetime or a string type. The time must be a datetime.
Example

MAKEDATETIME("1899-12-30", #07:59:00#) = #12/30/1899 7:59:00 AM#

MAKEDATETIME([Date], [Time]) = #1/1/2001 6:00:00 AM#

Notes

This function is available only for MySQL-compatible connections (which for Tableau are MySQL and Amazon Aurora).

MAKETIME is a similar function available for Tableau Data Extracts and some other data sources.

MAKELINE

SyntaxMAKELINE(<Spatial Point1>,<Spatial Point2>)
OutputGeometry spatial object (line)
DefinitionGenerates a line mark between two points.
Example
MAKELINE(OriginPoint, DestinationPoint)
MAKELINE( MAKEPOINT(OriginLat],[OriginLong]) , MAKEPOINT([DestinationLat],[DestinationLong] )
NotesUseful for building origin-destination maps or, with MAKEPOINT, turning latitude and longitude into spatial objects.

MAKEPOINT

SyntaxMAKEPOINT(<latitude>, <longitude>)
OutputGeometry spatial object (point)
DefinitionConverts data from latitude and longitude columns into spatial objects.
Example
MAKEPOINT([AirportLatitude],[AirportLongitude])
Notes

You can use MAKEPOINT to spatially-enable a data source so that it can be joined with a spatial file using a spatial join. For more information, see Join Spatial Files in Tableau.

To use MAKEPOINT, your data must contain latitude and longitude coordinates.

MAKETIME

SyntaxMAKETIME(hour, minute, second)
OutputDatetime. See Notes.
DefinitionReturns a date value constructed from the specified hour, minute and second.
Example
MAKETIME(14, 52, 40) = #1/1/1899 14:52:40#
Notes

Because Tableau does not support a time data type, only datetime, the output is a datetime. The date portion of the field will be 1/1/1899.

Similar function to MAKEDATETIME, which is only available for MYSQL-compatible connections.

STR

SyntaxSTR(expression)
OutputString
DefinitionCasts its argument as a string.
Example
STR([ID])

Cast Boolean expressions

A Boolean can be cast to an integer, float or string, but not a date.

  • Truemaps to 1, 1.0 or "1"
  • False maps to 0, 0.0 or "0"
  • Unknown maps to Null

Create a type conversion calculation

Follow along with the steps below to learn how to create a type conversion calculation.

  1. In Tableau Desktop, connect to the Sample - Superstore saved data source, which comes with Tableau.
  2. Navigate to a worksheet.
  3. Select Analysis > Create Calculated Field.
  4. In the calculation editor that opens, converts the Postcode field from a number to a string:
    • Name the calculated field, Post Code String.
    • Enter the following formula:

      STR([Postal Code])

    • When finished, click OK.

The new calculated field appears under Dimensions in the Data pane. Just like your other fields, you can use it in one or more visualisations.

Converting this field from a number to a string ensures that Tableau treats it as a string and not a number (and therefore doesn't aggregate it).

See Also

Data Types

Convert a Field to a Date Field

Formatting Calculations in Tableau

Functions in Tableau

Tableau Functions (Alphabetical)

Tableau Functions (by Category)

Thanks for your feedback!Your feedback has been successfully submitted. Thank you!