Reputation: 25
I have a table which contain a date dimension (with data for a couple of years) with several metrics. I want to be able to add the metric with the value of last year in the same table with standard metric that shows the value for the selected time period.
Example - current table in data studio:
What i need is to create a metric1_lastyear
that would display the value of that same metric during the same selected date period but for the previous year.
Upvotes: 1
Views: 8864
Reputation: 3411
To solve this, you'll need to blend your Data Source with itself.
First, create a calculated column with the comparison date:
Prev_Date
: DATE(DATETIME_SUB(Date, INTERVAL 1 MONTH))
You can change the comparison criteria with anything you wish (eg. INTERVAL 1 YEAR, etc). Check DATETIME_SUB documentation for more information.
After this, create a new data view (Resources > Manage blended data > Add a data view), and add your Data Source twice, as follows:
Notice how I join the Prev_Date
with Date
and that the column Prev_value
in the second Data Source actually is the Value
column (I just renamed it to be able to distinguish them).
And there you are:
Here is an example report that I used to take snapshots (they're both public and editable, to let you check them):
Upvotes: 3