Tableau: Compare Same Period Last Year

Step 1:

Create a crosstab by dragging order date to rows, and sales to the text shelf. In this data, we only have December 2019 and 2020. In 2020, the data ends at the 20th of the month.

Step 2:

Create a calculation for this year sales by using this calculated field.

if year([Order Date]) = year({Max([Order Date])}) then [Sales] END

Step 3:

Copy the calculated field and modify it for last year.

if year([Order Date]) = year({Max([Order Date])})-1 then [Sales] END

Step 4:

In order to only compare month to date for 2019, we’ll need to add a filter. Use this calculation to test if the day is less than the max day in 2020.

day([Order Date]) <= day({max([Order Date])})

Step 5:

Drag that calculation to the filter shelf, and keep only True values

Step 6:

Now, you can remove the order date pill, and create a bar chart by dragging measure values to the row shelf.