Select Page

DATE TIME FUNCTIONS IN TABLEAU

In this blog, I will work with date and time functions and calculations. so let’s start by learning how to work with dates in Tableau.

Date and time as data types

Deriving Date (Time) from other columns

What if we do not have a date field in our dataset, but we have the columns where we can derive the date from?

Example:

Date Field:   MAKEDATE ([Year], [Month], [Day])

Time Field:    MAKETIME ([Hour], [Minute], [Second])

Date Time Field:   MAKEDATETIME ([Date], [Time])

Parsing dates

What if we do not have a date type field in our dataset, but we have a string column where we can derive the date from?

DATEPARSE (Format, String)

Example:

DATEPARSE(‘YYYY-MM-dd HH:mm:ss aa’, [Transaction date])

Extracting date parts

The DATEPART function Extracts a discrete year, quarter, month, day, day of year, weekday, hour, minute, second, etc.

Example:

DATEPART(‘Year’,[Order Date])

DATEPART(‘quarter’,[Order Date])

Truncating dates

The DATETRUNC function truncates, or, in other words, shorts or cuts the date to the specified date defined by you.

Example:

DATETRUNC(‘month’, #2022-09-16#)  à Returns 1 Dec 2022

DATETRUNC(‘quarter’, #2022-09-16#)  à Returns Q3

* Referring to a date in calculation using hard-coded dates: E.g. #2022-09-16#

Calculating with dates

• Adding intervals to dates

DATEADD(date_part,interval,[Date]) à Returns a date

Example:

• Subtracting intervals from dates

DATEDIFF(date_part,date1,date2) à Returns a number

Example:

DATEDIFF(‘month’,[Start],[End])

DATEDIFF(‘day’,[Start],[End])

What is time series analysis?

It is a study of data in particular periods or intervals. It may involve trend analysis, forecasting, and comparisons of data across various seasons and rolling time periods.