Bernard K

Feb 9, 2023

Tableau’s DATEADD () Function

Introduction

DATEADD () is a Tableau function that adds an increment to a specific date returning a new date. The increment is defined by the interval and the date_part.

SYNTAX

DATEADD (date_part, interval, date)

Example

DATEADD (‘day’, 5, #2023-01-20#) = #2023-01-25#

Where date_part=’day’, interval=5

(The above function adds 5 days to the date returning #2023-01-25#)

The date_part is a string and can take any of the following.

  • ‘second’ – ‘0-59’

  • ‘minute’ – ‘0-59’

  • ‘hour’ – ‘0-23’

  • ‘day’ – ‘1-31’

  • ‘weekday’ – ‘1-7’

  • ‘dayofyear’ – ‘1-366’

  • ‘week’ – ‘1-53’

  • ‘month’ – ‘1-12’

  • ‘quarter’ – ‘1-4’

  • ‘year’ – e.g., 2023

  • ‘iso-weekday’ – ‘1-7’

  • ‘iso-week’ – ‘1-53’

  • ‘iso-quarter’ – ‘1-4’

  • ‘iso-year’ – e.g., 2023

The interval is an integer which can take both positive (+ve) and negative (-ve) values.

For example, to subtract 2 months from a date field, one can use the following calculation.

DATEADD (‘month’, -2, #2023-02-09#) = #2022-12-09#

(Which subtracts 2 months from the current date returning #2022-12-09#)

Dynamic DATEADD () Function with Tableau parameters

Sometimes you can make your DATEADD calculations dynamic by simply using a parameter.

To do that, create a string parameter that contains the date_parts to be applied in the calculation.

Next, add this parameter ‘Select date_part’ on the date_part section of your DATEADD calculation as shown below.

With this calculation you can compute the ‘New Order Date’ by adding an increment of 2 units of the selected date_part on your parameter.

Note, you can also use an integer parameter to adjust the interval dynamically.

Conclusion

If this post was helpful and you would like to receive more of these Tableau tips and tricks, kindly subscribe to our mailing list below.

If you like the work we do and would like to work with us, drop us an email on our Contacts page and we’ll reach out!

Thank you for reading!