How do I calculate the number of days in a month?

How do I calculate the number of days in a month?

Hi @jcolucci,

To calculate the number of days in a month, you can:

  1. Truncate the original date to the first day of its month using truncDate('MM', Date).
  2. Add one month to that truncated date using addDateTime(1, 'MM', truncDate('MM', Date)).
  3. Calculate the difference in days between these two dates.

That looks like this:

dateDiff(
  truncDate('MM', Date),
  addDateTime(1, 'MM', truncDate('MM', Date)),
  'DD'
)

how-do-i-calculate-the-number-of-days-in-a-month/40783

1 Like

Hi Rob, good morning!
This solution is not working for Quicksight.



Hi @jcolucci -

You need to use days_in_month as a GROUP BY or take the MAX instead of the default SUM if you are going to use it as VALUE

Example:

Good morning!

Thanks, Rob! The problem has been solved.

1 Like