Looking for the Perfect Date using AtScale and Tableau

Looking For The Perfect Date Using AtScale And Tableau

My previous blog highlighted some best practices to gain immediate value from all the capabilities that AtScale offers when using Tableau as your BI tool of choice. One of those best practices is to use AtScale-created date dimensions to improve query performance, which is particularly helpful when using date dimensions as filters.

See AtScale Intelligence Platform in action, Sign up for this webinar!

But what about using date dimensions to compare period over period? Is there a perfect way to implement custom date comparisons using AtScale and Tableau? Can we create an analysis experience for the business user that is both time intelligent and visually appealing? Definitely! This article describes the most flexible implementation for creating time intelligent analysis using AtScale and Tableau.

The best way to allow for flexible date comparisons would be to create a calculated field that contains the required date comparisons, and the supporting parameters needed to run the calculations.

Step 1: Create Parameters required for date calculations.

  1. Create a parameter called “Analysis Type”, with values of the types of Analysis comparisons that are required. In this case, we are looking at Rolling Period, Year over Year, Month over Month and YTD (see screenshot)

Screen%20Shot%202018-04-24%20at%205.00.32%20AM

  1. Create a parameter called “Custom Date”, which allows the user to input any date they want, and then can be used in other parameters and calculations (see screenshot)

Screen%20Shot%202018-04-24%20at%205.01.42%20AM

  1. Create a parameter called “Date Chooser”, which allows the user to specify the date to be used in the comparisons. In this example, we are using 2 values: Today and Custom Date.

Screen%20Shot%202018-04-24%20at%205.02.45%20AM

  1. Create a parameter called “Period Length”, which allows the user to how many periods are to be evaluated. In this example, we are using 12.

Screen%20Shot%202018-04-24%20at%205.03.40%20AM

  1. Create a parameter called “Period Type”, which allows the user to specify the date part to use in their comparisons. In the example below, we are using Day, week, month, quarter and year.

Screen%20Shot%202018-04-24%20at%205.04.37%20AM

  1. For all the newly created parameters, right click and select “show parameter control” so they can all be seen on the view.

Step 2: Create Calculated Fields that use new parameters

  1. Create a calculated field called “DateComparisonToUse” , which calls the “Date Chooser” Parameter.

Screen%20Shot%202018-04-24%20at%205.06.15%20AM

  1. Create a calculated field called “DateforIndex”, which calls the “Period Type” parameter to be used in an Index calculation.

Screen%20Shot%202018-04-24%20at%205.07.17%20AM

Step 3: Create Calculated Field called “Analysis Calculations”, which uses the new parameters and calculated fields to create the different date comparisons the user wants to see

CASE [Analysis Type]

WHEN ‘YoY’ THEN

IF DATEDIFF([Period Type],[Date],[DateComparisonToUse]) >=0 AND DATEDIFF([Period Type],[Date],[DateComparisonToUse])< [Period Length] THEN 0 ELSEIF DATEDIFF([Period Type],[Date],DATEADD(‘year’,-1,[DateComparisonToUse])) >=0 AND DATEDIFF([Period Type],[Date],DATEADD(‘year’,-1,[DateComparisonToUse])) < [Period Length] THEN -1 END

WHEN ‘MoM’ THEN

IF DATEDIFF([Period Type],[Date],[DateComparisonToUse]) >=0 AND DATEDIFF([Period Type],[Date],[DateComparisonToUse])< [Period Length] THEN 0

ELSEIF DATEDIFF([Period Type],[Date],[DateComparisonToUse]) >= [Period Length] AND DATEDIFF([Period Type],[Date],[DateComparisonToUse]) <2*[Period Length] THEN -1

END

WHEN ‘RP’ THEN
IF DATEDIFF([Period Type],[Date],[DateComparisonToUse]) >=0 AND DATEDIFF([Period Type],[Date],[DateComparisonToUse])< [Period Length] THEN 0
ELSEIF DATEDIFF([Period Type],[Date],[DateComparisonToUse]) >= [Period Length] AND DATEDIFF([Period Type],[Date],[DateComparisonToUse]) <2*[Period Length] THEN -1
END

WHEN ‘YTD’ THEN

IF DATEPART(‘dayofyear’,[Date]) <= DATEPART(‘dayofyear’,[DateComparisonToUse]) THEN

// The case statement determines if the date is in the same year or the previous year. Any other years are null.

CASE YEAR([Date]) – YEAR([DateComparisonToUse])

WHEN 0 THEN 0

WHEN -1 THEN -1

                               END

             END

END

For ‘YoY’, ‘MoM’ and ‘RP’, the first statement sets the conditions for a date to be considered the “selected period”. It will check every date to the date we’ve chosen as our starting point. It must be based on whatever date we’ve chosen and go back a user chosen number of months, weeks, days etc. If the difference between these dates is >=0 and < our Period Length we consider it to be the ‘selected period’.

For ‘YTD’ we check every date in our view and see it would come before our selected date in a calendar year. If it does then we pass it to the case statement below if not we exit out and it is null. The case statement determines if the date is in the same year or the previous year. Any other years are null.

Our example shows a line graph comparing YTD from the current period (in orange), to a previous period (blue). The current period is not a full year yet, so the line only extends partially across the axis.

Step 4 – Create the View

Screen%20Shot%202018-04-24%20at%205.28.52%20AM

  1. Set the Parameters to the screenshot values.
  2. Place the “Analysis Calculations” field on the Rows. Right click and select “filter” and then de-select “Not Being Used”
    Screen%20Shot%202018-04-24%20at%205.30.01%20AM
  3. Place the Sales TY Measure on the row next to the “Analysis Calculations” field.
  4. Place the “DateforIndex” field on the “Details” shelf. Right click and select “exact date and continuous”. The Pill should be green.
  5. In the Column shelf, type in “index()”. Then right click and select Table Calc – Compute Using DateforIndex. The index() calculation evaluates the values in the equation and reduces them to just whole numbers like “1, 2, 3…”

Screen%20Shot%202018-04-24%20at%205.31.32%20AM

  1. If you change the parameters to the following: Analysis Type = Year over Year and Period Type = Months, you will get the following result.
    Screen%20Shot%202018-04-24%20at%205.32.47%20AM

This view shows the Year span in but month slices of 12 and metrics reflex the month sum.
We hope the approach described in this article allows you to create insightful time-based reporting to get the most out of your AtScale and Tableau investments.

We invite you to learn more about AtScale today!

See AtScale Intelligence Platform in action, Sign up for this webinar!