How to display data for the last N months on a graph and show year-on-year comparisons in the tooltip
Published: 07 Apr 2022 Last Modified Date: 07 Apr 2022
Question
How to display data for the last N months on a graph and show year-on-year comparisons in the tooltip
Environment
Tableau Desktop
Answer
In the following example, you want to display the last 10 months.
<STEP 1> -Creating bar chart- 1. Connect to Sample -Superstore. 2. Drag [Order Date] to Columns and [Sales] to Rows. 3. Expand [YEAR(Order Date)] and display up to MONTH. 4. Remove [QUARTER] from Columns.
<STEP 2> -Calculate year-on-year comparisons- 5. Create a new calculated field like the following. Name : year-on-year Calculation : SUM([Sales]) / LOOKUP(SUM([Sales]),-12) 6. Right-click on [year-on-year] > Default Properties > Number Format > Percentage > OK 7. Drag [year-on-year] to Detail.
<STEP 3> -Filtered in the last 10 months- 8. Create a new calculated field like the following. Name : Filter Calculation : INDEX() <= 10 9. Drag [Filter] to Filters Pane > Click on 'All' > OK 10. Right-click on [Filter] in Filter Pane > Edit Table Calculation > Set as following. 11. Right-click on [Filter] in Filter Pane > Edit Filter > uncheck 'False' > OK
Thank you for providing your feedback on the effectiveness of the article.