Tableau provides various Type Conversion Functions to perform type casting on our data. They are DATE, DATYETIME, 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 Work sheet. So, Please refer Connecting to 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 string. Syntax of this Tableau STR Function is:
To demonstrate these conversion functions, we have to use Calculated Fields. In order 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, window will be opened. Here, we renamed the default calculation name as STRFunc.
Below statement will convert the Hire date to String
Let me add this STR function field to existing table (by dragging 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. Syntax of this Tableau Date Function is:
Let me use this function on StrFunc which holds Hire Date in string format.
From the below screenshot, you can see the Date function returned date from string column.
Tableau DATETIME Function
The Tableau Datetime function returns date and time from given expression, string, or number. Syntax of this Tableau Datetime Function is:
Let me use this datetime function on StrFunc which holds Hire Date in string format.
Tableau INT Function
The Tableau INT function returns integer from a given expression. Syntax of this Tableau INT Function is:
Let me use this function on Sales column which holds Float values.
Tableau FLOAT Function
The Tableau FLOAT function converts given expression to float. Syntax of this Tableau FLOAT Function is:
Let me use this function on 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. Syntax of this Tableau Dateparse Function is:
Let me use this function on StrFunc which holds Hire Date in string format. remember, given format should match the data inside the column
DATEPARSE('yyyy-MM-dd h:m:s.SSSS', [STRFunc])