How do I create a formula for only the last month of data from the max date in Tableau?
- Tableau FAQs
- December 11, 2018
To calculate the last month by date, you can approach it in two different ways:
– You can first create a calculated column MAX ([dueDate]) in which you will find the last date in the dataset, then you need to create a calculated column DATE(DATETRUNC(‘month,’ [MaxDate])) in which you will get the beginning of the last month from the previous calculated field.
DATE(DATETRUNC('month', [MaxDate]))
DATE() – this function converts the received format to Date format
DATETRUNC(‘month,’ [MaxDate]) – this function returns the month from the date, and here you must specify the date detail (day, month, year, etc.) and specify the field from which you want to extract this data
– The next way is useful if you need to calculate the last month with LOD, it will look like this:
{FIXED [ProductIDGroup]: DATETRUNC('month', DATE(MAX([DueDate])))}
{FIXED [ProductIDGroup]: – here, we fix the level of detail to display the last month of the date
DATETRUNC(‘month’, DATE(MAX([DueDate])))} – this part is described above