Google Data Studio time dimensions slider for series chart
I’m really disappointed when a dashboard made for weekly or monthly basis are used with a date range of…one day, especially when we talk about time series charts and related trends…disappearing…and becoming a kind of simple score card, lost in the space.
The opposite is also true: A time series chart with plots and labels is easily overloaded if the selected date range is too large.
So, let’s try to provide some controls on time series chart to change the time dimension for greater clarity or more time granularity, switching as example from daily plots to hours if we select only one day of data.
It is a new opportunity to use the amazing new feature of Data Studio: parameter 😋
Comparing to my previous article about primary and secondary dimension selection, we will use the same kind of mechanism to select dimension through parameter. but this time, we will play with slider control and date formats.
Let’s see this new combination of Data Studio built-in features, customized to address a specific viz requirement for interactive reader experience.
Ingredients to create the mechanism of time dimensions slider
To get this time dimension slider, we will use the following native features provided by Google Data Studio:
- Data source parameter
We will use it to store our 4 levels of time data
- Calculated fields
To wrap the parameter as a calculated field and to map the selected option of the parameter with the related dimension to display (meta data to data)
- Slider control
for the dynamic selection of time dimensions, from the smaller (hour) to the bigger (month)
- Line chart
Finally, to display our data, we use line chart with time dimension as text to be able to switch format a level to another without be limited by date format
Data source parameter
Let’s create a parameter inside our data source to store the options we wish to propose through the slider. In this example I use a Google Analytics data source providing me Hour and Date basic dimension. I will use them in the next steps.
In the example below, we will create Time dimension slider parameter as a range of integers, from 1 to 4. Sliders can only be used with numeric values. So we need to create a parameter based on integers, then map each integer with the right dimension.
- 1 for Hour
- 2 for Day (default value)
- 3 for Week
- 4 for Month
Now, we need the following calculated fields. I use “TDS” as prefix for “Time dimensions slider”.
Let’s begin with our 4 levels of time dimensions cast as text:
TDS – Hour as text
CAST(Hour AS TEXT)
TDS – Date as text
CAST(TODATE(Date, "%Y-%m-%d") AS TEXT)
TDS - Week as text
CAST(TODATE(Date,"%Y W%W") AS TEXT)
TDS - Month as text
CAST(TODATE(Date, "%Y-%m") AS TEXT)
Then, let’s create a wrapper inside a calculated dimension just to be able to use the parameter easily in the next steps (current technical limitations, already identified by Data Studio team) inside other calculated dimensions without constraints:
TDS - Time dimension slider param - dim wrp
Time dimension slider
We also need a calculated field to display a dimension label at the right of the slider. We plan to put some icons at the top of the slider, but let’s give also this information with a clear text. So for each value of the parameter, so the dimension wrapper, corresponds also a label, managed with a simple CASE statement.
TDS - Time dimension label
CASE WHEN TDS - Time dimension slider param - dim wrp = 1 THEN "Hour" WHEN TDS - Time dimension slider param - dim wrp = 2 THEN "Day" WHEN TDS - Time dimension slider param - dim wrp = 3 THEN "Week" WHEN TDS - Time dimension slider param - dim wrp = 4 THEN "Month" ELSE "Day" END
At last, we create the dimension that we will use inside the line chart.
TDS - Selected time dimension
CASE WHEN TDS - Time dimension label = "Hour" THEN TDS - Hour as text WHEN TDS - Time dimension label = "Day" THEN TDS - Date as text WHEN TDS - Time dimension label = "Week" THEN TDS - Week as text WHEN TDS - Time dimension label = "Month" THEN TDS - Month as text END
Slider control and related label
Now the configuration of the data source is finished, we add the slider and we select the parameter Time dimension slider as control field (Data tab) and adapt styles. We must also define 1 for the step size the the snapping options.
We can also decorate it with 4 icons located on the 4 possible static positions.
Then, we add at the right of the slider, a table chart with one line, displaying TDS – Time dimension label dimension without metrics and with a light style (contextual info)
Our last action is the change of the time series chart to a line chart with:
- TDS – Selected time dimension as primary dimension
- Here, Sessions as metric
- Sorting by TDS – Selected time dimension ASC to respect the time series sorting
- Adapted other configurations and styles
Then, we test the final result and the interaction between the slider and the displayed data.
Voilà! It’s ready.
Alternative version for a better data viz
I’ve also created a compact version of this slider because this kind of feature should not require a lot of space. It helps for an easier insertion in a dashboard. In the version below, I’ve also applied the same graphic styles than a kind of extended legend to create even more consistency. If your trend is designed with a bar chart or if you display several metrics, you can use a neutral color to avoid bad understanding.
I definitely prefer this compacted version.
Before the launching of parameters feature inside Google Data Studio, my initial wish was to create an automatic and adaptative selection of time dimension following the dates range selected by the report reader, and so the number of days. Because of some limitations about CASE statement and melting aggregated and not aggregated data, I never succeed to this project. I hope that one day it will be possible. If so, combining automatic behaviour with control like described in this article will be even better.
If you need to play with this custom slider, you can test the following Google Data Studio report, changing the date range and the time granularity of the series chart. Cheers!