Do you know how to compare selected and previous months in Tableau?
Follow along to the video or check out the steps below.
Let’s compare the selected month with the previous month.
- Create a calculated field named “Order Month” with the following formula:
DATE(DATETRUNC(‘month’, [Order Date]))
- Create a parameter named “Date” with:
Data type: Date
Allowable values: List
When workbook opens: Order Month (newly created field)
Display format: Custom MMM-yyyy
Right click it and “Show Parameter”
- Create a new calculated field called “Show Me Month” with the following formula:
IF [Order Month] = [Date]
ELSEIF [Order Month] = DATE(DATEADD(‘month’, -1, [Date]))
And convert it to discrete.
This will make all the rows with the same month as the selected one show 1 and all the rows with the previous month of the selected show as -1, all the rest will be 0.
- Bring the Order Month pill to the Rows shelf, right click it and select Month (the one with Month and Year), and Discrete
- Bring the Sales pill to the Columns shelf (you can select the Bar in the Mark shelf) and use the Show Me Month as filter, selecting the -1 and 1.
- Now you have a graph with the selected month and the previous month:
- You can format the numbers, colours, and use this technique with other graphs and even use the “Show Me Month” as a part of the formula of your calculated fields to show values for the selected and previous months.