• Skip to primary navigation
  • Skip to main content
Antichaos

Antichaos

Tableau, Data Analyse & Visualisatie

  • Home
  • Consultancy
  • Training
  • Blog
  • About Me
  • Newletter
  • Contact
  • Show Search
Hide Search

Calculate last day of month

Johan de Groot · 20 June 2017 ·

Sometimes you need to calculate how many days a certain month – like the current month. With some nested date-calculations this isn’t that hard to calculate…

First the complete formula:

<strong>DATEPART('day',DATEADD('day',-1,DATETRUNC('month',DATEADD('month',1,TODAY()))))</strong>

This calculations uses 3 different Tableau functions: DATEPART, DATEADD and DATETRUNC:

Step 1: Add 1 month to the date

Add 1 month to the date of today; this date will never exceed the last day of next month (adding 1 month to Jan 31 2019 will result in Feb 28 2019)

2017-05-29 -> 2017-06-29

DATEADD('month',1,TODAY())

Step 2: Get the first day of that next month

Truncate “today +1 month” to the first of the month: 2017-06-29 to 2017-06-01

DATETRUNC('month',DATEADD('month',1,TODAY())

Step 3: Substract one day

Substract one day of ‘the first of the month truncated to month 2017-06-01 -> 2017-05-31

DATEADD('day',-1,DATETRUNC('month',DATEADD('month',1,TODAY())))

Step 4: Day of month (optional)

DATEPART('day',DATEADD('day',-1,DATETRUNC('month',DATEADD('month',1,TODAY()))))

The day-number of that date is the number of days of this month

2017-06-01 > 31

Instead of the number of days of this month you can of course use any date – just replace TODAY() by the [Date] field in your datasource.

Related posts:

Top 2000 – 2018 Default ThumbnailUse Python as an Alteryx connector Default ThumbnailISO weeks in Tableau Bohemian Rhapsody: From Top 2000 to jump-chart

blog, blog-en

Need help?

Contact me if you need Tableau help on development, implementation or training!
contact@antichaos.net

The Antichaos Update

Like what you’re seeing? Let’s stay in touch!

(The Antichaos update is a short, infrequent newsletter on data, Tableau, usability and more!)

Follow me on LinkedIn

Follow me (and connect!) on LinkedIn to stay up-to-date. Connect on LinkedIn

Antichaos

Copyright © 2025