Tableau: Dynamically Display The Last n Months From Today

Step 1:

Build a bar chart using Month([Date]) and sum([Sales])

Step 2:

Create a new parameter as an integer. Set the default value to 12

Step 3:

Write a calculation to test if the month is greater than or equal to today’s date minus n months. Pass the parameter into the n value.

DATETRUNC(‘month’, [Date])

>=

DATEADD(‘month’, -[n Months], DATETRUNC(‘month’, today()))

Step 4:

Drag the field to the filter shelf, and only keep true values. Test with your parameter value.

Tableau: Dynamically Display The Last n Months From Today