Tableau provides various Type Conversion Functions to perform typecasting on our data. They are Tableau DATE, DATETIME, DATEPARSE, INT, FLOAT, SRT, etc. In this article, we will show you how to use Tableau Conversion Functions with examples.
To demonstrate these Tableau Conversion Functions, we are going to use the below shown data. As you can see, there are 15 records in this table.
Remember, this is an Excel Worksheet. So, Please refer Connecting to the Excel Files article to understand the connection settings.
Tableau Conversion Functions
The following examples will show you the list of Conversion Functions in Tableau
Tableau STR Function
The Tableau STR function converts the given expression to a string. The syntax of this Tableau STR Function is:
To demonstrate these Tableau conversion functions, we have to use Calculated Fields. To create a calculated field, please navigate to Analysis Tab and select Create Calculated Field… option as shown below.
Once you click on the Create Calculated Field… option, a window will be opened. Here, we renamed the default calculation name as STRFunc.
The below Tableau str statement will convert the Hire date to String
Let me add this STR function field to an existing table (by dragging a field to Rows Shelf). Please refer Create Table Report article to understand the process of creating a table
Tableau DATE Function
The Tableau Date function returns date from given expression, number, or string. The syntax of this Tableau Date Function is:
Let me use this Tableau date function on StrFunc, which holds Hire Date in string format.
From the below screenshot, you can see the Tableau Date function returned the date from the string column.
Tableau DATETIME Function
The Tableau DateTime function is one of the Tableau conversion function, which returns date and time from a given expression, string, or number. The syntax of this Tableau Datetime Function is:
Let me use this Tableau DateTime function on StrFunc, which holds HireDate in string format.
Tableau INT Function
The Tableau INT function returns an integer from a given expression. The syntax of this Tableau INT Function is:
Let me use this function on the Sales column, which holds Float values.
Tableau FLOAT Function
The Tableau FLOAT is one of the Tableau conversion function which converts given expression to float. The syntax of the Tableau FLOAT Function is:
Let me use this Tableau float function on the income column, which has int values.
Tableau DATEPARSE Function
The Tableau Dateparse function parse and returns date and time from given expression, number, or string. The syntax of this Tableau Dateparse Function is:
Let me use this Tableau DateParse function on StrFunc, which has a string format of Hire Date. Remember, given format should match the data inside the column
DATEPARSE('yyyy-MM-dd h:m:s.SSSS', [STRFunc])