Tableau Date Functions with Examples
Dates are crucial fields which are widely used in data analysis. Hence, Tableau provides a large number of inbuilt date functions that allows you to manipulate dates in your data source. You can simply add or subtract days from a date or can create complex expressions involving dates. You can also create new date values with a specified date function, by using the DATETRUNC function.
Create Calculated Field
- In the Tableau Desktop, connect to the Excel file named Facebook Data which is saved in the data source.
- Navigate to the worksheet pane and click on Analysis > Create Calculated Field as shown below.
- You will notice that a new dialogue box has appeared. Click on the icon present on the rightmost side of the box.
- You can see a tab linked with the previous one which lists all the functions that are available in Tableau.
- Further, you can change the dropdown value and choose only the functions that are related to Date.
- On the rightmost side of the pane, you will notice that Tableau is briefing us with the formula and small explanation for the selected functions.
Create a Formula
Now, find out the sales volume along with the addition to the date of sales in months from 12
st March 2018. For this, we will use the ‘DATEADD’ Date function and will create the formula as shown in the following screenshot. Also, change the name to
DateAdd. And click on OK.
In the Data pane, under Dimensions, you will notice a field has been created named
Date_Add.
Applying the Calculated Field
The above-calculated field can be applied in the view by dragging it to the Rows and drag the Sales field to the Columns shelf. Also, drag the Date with months. The following screenshot shows the Sales values.