---
schema_version: "1"
id: 2968adb244e839262607104fd0ff01de0f25a3d8cfef978287bb2c640e4764b6
title: Type Conversion
collection: tableau
version: current
locale: en-gb
portal_url: https://docs.salesforce.com/tableau/current/en-gb/public/desktop/functions_functions_typeconversion.md
canonical_url: https://help.tableau.com/current/public/desktop/en-gb/functions_functions_typeconversion.htm
source_site: help.tableau.com
content_type: documentation
content_hash: f526dd50cf567655086aa349680bf27ec17157c11b6adf900c6afadb9feab9aa
description: Reference for type conversion functions that cast fields between data types.
---
[Skip to main content](#main-content)

# 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](/tableau/current/en-gb/public/desktop/en-gb/Img/function_typeconversion_error.png)

> [!TIP]
> 
>  Fields have default [Data Types](https://help.tableau.com/current/public/desktop/en-gb/datafields_typesandroles_datatypes.htm) 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

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>DATE(expression)</code></td></tr><tr><td>Output</td><td>Date</td></tr><tr><td>Definition</td><td>Returns a date, given a number, string or date expression.</td></tr><tr><td>Example</td><td><pre>DATE([Employee Start Date])</pre><pre>DATE("September 22, 2018") </pre><pre xml:space="preserve">DATE("9/22/2018")</pre><pre>DATE(#2018-09-22 14:52#)</pre></td></tr><tr><td>Notes</td><td><p>Unlike <a href="https://help.tableau.com/v0.0/pro/desktop/en-gb/functions_functions_date.htm#dateparse" target="_blank">DATEPARSE</a>, 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.</p><p><a href="https://help.tableau.com/v0.0/pro/desktop/en-gb/functions_functions_date.htm#makedate" target="_blank">MAKEDATE</a> is another similar function, but MAKEDATE requires the input of numeric values for year, month and day.</p></td></tr></tbody></table>

### DATETIME

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>DATETIME(expression)</code></td></tr><tr><td>Output</td><td>Datetime</td></tr><tr><td>Definition</td><td>Returns a datetime given a number, string or date expression.</td></tr><tr><td>Example</td><td><pre>DATETIME("April 15, 2005 07:59:00") = April 15, 2005 07:59:00</pre></td></tr></tbody></table>

### FLOAT

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>FLOAT(expression)</code></td></tr><tr><td>Output</td><td>Floating point number (decimal)</td></tr><tr><td>Definition</td><td>Casts its argument as a floating point number.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">FLOAT(3) = 3.000</pre></td></tr><tr><td>Notes</td><td>See also INT, which returns an integer.</td></tr></tbody></table>

### INT

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>INT(expression)</code></td></tr><tr><td>Output</td><td>Integer</td></tr><tr><td>Definition</td><td>Casts its argument as an integer. For expressions, this function truncates results to the closest integer toward zero.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">INT(8/3) = 2</pre><pre xml:space="preserve">INT(-9.7) = -9</pre></td></tr><tr><td>Notes</td><td><p>When a string is converted to an integer it is first converted to a float and then rounded.</p><p>See also FLOAT, which returns a decimal.<br>See also <a href="https://help.tableau.com/current/pro/desktop/en-gb/functions_functions_number.htm#round" target="_blank">ROUND</a>, <a href="https://help.tableau.com/current/pro/desktop/en-gb/functions_functions_number.htm#ceiling" target="_blank">CEILING</a> and <a href="https://help.tableau.com/current/pro/desktop/en-gb/functions_functions_number.htm#floor" target="_blank">FLOOR</a></p></td></tr></tbody></table>

### MAKEDATE

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MAKEDATE(year, month, day)</code></td></tr><tr><td>Output</td><td>Date</td></tr><tr><td>Definition</td><td>Returns a date value constructed from the specified numerical year, month and date.</td></tr><tr><td>Example</td><td><pre>MAKEDATE(1986,3,25) = #1986-03-25#</pre><p>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.</p></td></tr><tr><td>Notes</td><td><p>Available for Tableau Data Extracts. Check for availability in other data sources.</p><p>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.</p></td></tr></tbody></table>

### MAKEDATETIME

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MAKEDATETIME(date, time)</code></td></tr><tr><td>Output</td><td>Datetime</td></tr><tr><td>Definition</td><td>Returns 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.</td></tr><tr><td>Example</td><td><p></p><pre>MAKEDATETIME("1899-12-30", #07:59:00#) = #12/30/1899 7:59:00 AM#</pre><p></p><p></p><pre>MAKEDATETIME([Date], [Time]) = #1/1/2001 6:00:00 AM#</pre><p></p></td></tr><tr><td>Notes</td><td><p>This function is available only for MySQL-compatible connections (which for Tableau are MySQL and Amazon Aurora).</p><p>MAKETIME is a similar function available for Tableau Data Extracts and some other data sources.</p></td></tr></tbody></table>

### MAKELINE

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MAKELINE(&lt;Spatial Point1&gt;,&lt;Spatial Point2&gt;)</code></td></tr><tr><td>Output</td><td>Geometry spatial object (line)</td></tr><tr><td>Definition</td><td>Generates a line mark between two points.</td></tr><tr><td>Example</td><td><pre>MAKELINE(OriginPoint, DestinationPoint)</pre><pre>MAKELINE( MAKEPOINT(OriginLat],[OriginLong]) , MAKEPOINT([DestinationLat],[DestinationLong] )</pre></td></tr><tr><td>Notes</td><td>Useful for building origin-destination maps or, with MAKEPOINT, turning latitude and longitude into spatial objects.</td></tr></tbody></table>

### MAKEPOINT

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MAKEPOINT(&lt;latitude&gt;, &lt;longitude&gt;)</code></td></tr><tr><td>Output</td><td>Geometry spatial object (point)</td></tr><tr><td>Definition</td><td>Converts data from latitude and longitude columns into spatial objects.</td></tr><tr><td>Example</td><td><pre>MAKEPOINT([AirportLatitude],[AirportLongitude])</pre></td></tr><tr><td>Notes</td><td><p>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 <a href="https://help.tableau.com/current/public/desktop/en-gb/maps_spatial_join.htm" class="xref">Join Spatial Files in Tableau</a>.</p><p>To use MAKEPOINT, your data must contain latitude and longitude coordinates.</p></td></tr></tbody></table>

### MAKETIME

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>MAKETIME(hour, minute, second)</code></td></tr><tr><td>Output</td><td>Datetime. See Notes.</td></tr><tr><td>Definition</td><td>Returns a date value constructed from the specified hour, minute and second.</td></tr><tr><td>Example</td><td><pre>MAKETIME(14, 52, 40) = #1/1/1899 14:52:40#</pre></td></tr><tr><td>Notes</td><td><p>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.</p><p>Similar function to MAKEDATETIME, which is only available for MYSQL-compatible connections.</p></td></tr></tbody></table>

### STR

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>STR(expression)</code></td></tr><tr><td>Output</td><td>String</td></tr><tr><td>Definition</td><td>Casts its argument as a string.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">STR([ID])</pre></td></tr></tbody></table>  

## Cast Boolean expressions

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

- `True`maps 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](https://help.tableau.com/current/public/desktop/en-gb/datafields_typesandroles_datatypes.htm)

[Convert a Field to a Date Field](https://help.tableau.com/current/public/desktop/en-gb/data_dateparse.htm)

[Writing Calculations in Tableau](https://help.tableau.com/current/public/desktop/en-gb/functions_operators.htm)

[Functions in Tableau](https://help.tableau.com/current/public/desktop/en-gb/functions.htm)

[Tableau Functions (Alphabetical)](https://help.tableau.com/current/public/desktop/en-gb/functions_all_alphabetical.htm)

[Tableau Functions (by Category)](https://help.tableau.com/current/public/desktop/en-gb/functions_all_categories.htm)