Date dimension is one of the most important dimensions in data structure. Most data are transactional ones with a timestamp attached to each transaction record. Needless to say, time series analysis is one of the most important analysis methods.
Let's get into the problem statement based on a simple example: two stores have their sales tallied in two tables (two data sources). The headquarter wants to view the overall sales along time.
Here are the very simplistic reports from the two stores:
The dates in the two stores are non-inclusive sets. Let's see how to use scaffold to blend the two tables together and create a single chart to view the overall sales.
Scaffolding
As we mentioned in Lossless Data Blending via Scaffolding, we need to build a superset of the dates in both tables. For date dimension it is much easier. It is a two-row table with the min date and the max date of combined set of dates in the two tables:
Note that the Scaffold Primary vs Secondary
Drag the Date to Columns shelf and turn on "Show Missing Values" in Scaffold's date pill, we will get all the dates in between. This is the KEY in blending date dimension!!
2.Blend Dates
Make sure all date dimensions from the secondary sources are linked with the primary.
3.Use ZN() to aggregate
We then create a measure Total Sales as
- ZN(SUM([Store A].[Sales]))+ZN( SUM([Store B].[Sales]))
Scaffolding with Parametric Dates
Data is dynamic. Especially the end date may not be fixed. We need to change the end date from time to time. It would be hard to change the static scaffold above.
We can use parameters for dates. Thus a parameter's default value and maximum value can be modified easily.
Here is the scaffold:
The we create a calculated field to set up Date dimension:
- Case [Record]
- WHEN 1 then [Start Date]
- WHEN 2 then [End Date]
- END
Here is the view of the resulting dashboard. Click it to go the interactive version.
This technique has been applied in this calculation:
Taking Stock with Start and End Dates
Taking Stock with Start and End Dates
Add a comment