Comparing selected and previous months in Tableau

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.

  1. Create a calculated field named “Order Month” with the following formula:
    DATE(DATETRUNC(‘month’, [Order Date]))

  1. 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”

comparing selected and previous months

  1. Create a new calculated field called “Show Me Month” with the following formula:
    IF [Order Month] = [Date]
    THEN 1
    ELSEIF [Order Month] = DATE(DATEADD(‘month’, -1, [Date]))
    THEN -1
    ELSE 0
    END

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.

comparing selected and previous months

  1. Bring the Order Month pill to the Rows shelf, right click it and select Month (the one with Month and Year), and Discrete

comparing selected and previous months

  1. 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.

comparing selected and previous months

  1. Now you have a graph with the selected month and the previous month:

  1. 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.

How to guides for Tableau beginners