Comprehensive Tableau Reference Guide: Calculated Field-Date Functions

Comprehensive Tableau Reference Guide: Calculated Field-Date Functions

Calculated fields in Tableau are new fields created by a user that are saved in the data store and can be applied for constructing more robust visualizations.

Comprehensive Tableau Reference Guide is a blog series covering the fundamentals of Tableau Software to help you develop a foundational knowledge of the Calculated Field functions. So, if you are a newbie planning to get started with Tableau or if you simply want to explore the popular features in Tableau, then these step-by-step guides are perfect for you.

In this bog, we shall discuss about the Date Functions that you can use after creating a calculated field. In the previous two articles of this blog series, we explored Logical Functions and Number Functions. Now, let’s begin our exploration of Date Functions.

  • To open the Calculated Field window, right-click anywhere over the Date window (sidebar) and the menu appears on the screen.

  • Select the option ‘’Create Calculated Field”. This brings up the Calculated Field window. If you right-click on a specific dimension or measure to create a calculation, then the formula text region of the Calculated Field displays it.

  • Next, select the option ‘’Date’’ from the drop-down menu under ‘’Functions’’. This filters the functions to display only a list of Date Functions.

  • The date_part, which is applied in a number of Date Functions, can take the following values:
  • Second (0-60)
  • Minute (0-59)
  • Hour (0-23)
  • Day (1-31)
  • Weekday (1-7 or use their names, i.e. ‘’Monday’’, etc.)
  • Week (1-52)
  • DayofYear (1-365)
  • Month (1-12 or use their names, i.e. ‘’December’’, etc.)
  • Quarter (1-4)
  • Year (four-digit representation)

Next, let’s examine the Date Functions one by one:

  • DATEADD Function

DATEADD(date_part, interval, date)

The DATEADD function enables a user to specify a part of a date and then increment it. This function alters the date by incrementing the date_part by the number mentioned in the interval. Example:

  • DATEDIFF Function

DATEIFF(date_part, date1, date 2, start_of_week)

This function returns the difference between date1 and date2, expressed in units decided by date_part. The parameter start_of_week is optional, and if it is undefined, then the associated data source determines the start of the week.

  • DATENAME Function

DATENAME(date_part, date, [start_of_week])

Using this function, the date_part parameter of the date is returned as a string. Here also, the start_of_week parameter isn’t compulsory. Example:

  • DATEPARSE Function

DATEPARSE(format, string)

This function works exactly in the opposite manner of DATENAME function. It converts a string into a date or time following the format specified by the user. In case the string and specified format don’t match, then a Null value is returned. Example:

  • DATEPART

DATEPART(date_part, date, start_of_week)

This function returns the date_part parameter of the date as an integer. Again, the start_of_week parameter isn’t compulsory. Example:

When the date_part parameter is set as weekday, start_of_date parameter is excluded, as in this case Tableau uses a specific order to apply offsets.

  • DATETRUNC

DATERUNC(date_part, date, start_of_week)

This function is used to round off the date to the accuracy specified in the date_part of the function. Example:

The start_of_week is optional, and if excluded, then the data source determines it.

  • DAY

DAY(date)

This function is used to return the day of a specific date as an integer. Example:

  • ISDATE

ISDATE(string)

This function runs a logical test and is also incorporated within the list of Logical Functions. It tests a string and indicates if a specified data is valid (true) or not (false). Example:

  • MAX Function

MAX(expression) or MAX(expr1, expr2)

The MAX function is included in other categories of functions too. This function is used to return the maximum of a singular expression across all records or the maximum between two expressions for each record. Both the arguments need to be of the same type. In case one of the arguments is NULL, it returns a NULL value. Example:

  • MIN Function

MIN(expression) or MIN(expr1, expr2)

Similar to the MAX function, MIN function is popularly used as a Number Function, but is also used as a Date Function. This function is used to return the minimum of a singular expression across all records or the minimum between two expressions for each record. Both the arguments need to be of the same type. In case one of the arguments is NULL, it returns a NULL value. Example:

  • MONTH

MONTH(date)

This function is used to return the month of a particular date as an integer. Example:

  • NOW

NOW()

This function is used to get the current date and time. Example:

  • TODAY

TODAY()

This function is used to get the current date. Example:

  • YEAR

YEAR(date)

This function is used to return the year of a particular date as an integer. Example:

Want to learn more about Tableau? Follow DexLab Analytics, one of the leading Tableau training institutes in Delhi, to read more blogs covering all the fantastic features in Tableau. Check back for articles covering Logical Functions and Number Functions. If you are looking for Tableau certification courses in Delhi, check DexLab’s online and classroom tableau training courses.

 

This article has been sourced from: https://interworks.com/blog/ccapitula/2015/04/15/tableau-essentials-calculated-fields-date-functions

 

Interested in a career in Data Analyst?

To learn more about Data Analyst with Advanced excel course – Enrol Now.
To learn more about Data Analyst with R Course – Enrol Now.
To learn more about Big Data Course – Enrol Now.

To learn more about Machine Learning Using Python and Spark – Enrol Now.
To learn more about Data Analyst with SAS Course – Enrol Now.
To learn more about Data Analyst with Apache Spark Course – Enrol Now.
To learn more about Data Analyst with Market Risk Analytics and Modelling Course – Enrol Now.

May 21, 2018 12:28 pm Published by , , , , , ,

, , , ,

Comments are closed here.

...

Call us to know more

×