Tableau - Date Truncation

Return the first day of the week, month, quarter or year using DATETRUNC


                    DATETRUNC(date_part, date, [start_of_week])
                     

The date_part can be:

  • day
  • week
  • month
  • quarter
  • year

[start_of_week] is an optional parameter which can be any day of the week (i.e "Monday", "Tuesday", etc)

Example

Return the first day of this year


                    DATETRUNC('year', TODAY())
                     

Return the first day of the quarter


                    DATETRUNC('quarter', TODAY())
                     

Return the first day of the month one year ago


                    DATETRUNC('month', TODAY() -365)
                     

Some tips:

  • Convert to an exact date
  • Change data type to discrete

These calculations come in handy when finding the number of days in the month, quarter or year dynamically.


Dash-Intel is a Power BI and Tableau resource site for data visualization and building BI dashboards.

Data Analyst & Consultant

Copyright 2015-2023 Dash-Intel.com Terms