How to build a parameter to switch between day, week or month in Looker Studio?
Ever wondered how to build a magic button to switch between day, week or month in Looker Studio? Search no more, we’ve got a solution !
Ok, you know the drill on your dataviz, shall it be a table, a time serie or a line graph: add a Drill down and you’ll be able to switch between day, week or month. But this is only applicable to one dataviz at the time, right? What if you wanted to change ALL your dataviz, at once? Well, in this article, we’ll show you how to a build a parameter to switch between day, week or month in Looker Studio. Pretty easy, whilst pretty powerful at the same time. Best of both worlds.
Looker Studio connectors we use on a daily basis and are happy with (w/ free trials): Supermetrics - Windsor - Catchr - PMA - Funnel
Not sure which one to pick? Reviews here and there. Still unsure?! Contact us with your tech stack and budget, and we’ll guide you in the right direction:
Let’s start with creating the parameter
First, let’s create a new parameter for your data source. Proceed to Resource on the top ribbon, Manage added data source, Edit and then Add a parameter top right corner. We’ll call it toggle, and provide 3 levels for List of values: Day, Week, Month, with Day being the default:
Save your parameter, and let’s move on to the new dimension.
Create a new dimension as a field
Back to the Field page, now Add a field, let’s call it New Date and copy the below formula:
CASE
WHEN toggle='Day' THEN date
WHEN Toggle='Week' THEN CAST(DATETIME_TRUNC(date,ISOWEEK) AS DATE)
WHEN Toggle='Month' THEN CAST(DATETIME_TRUNC(date,MONTH) AS DATE)
END
So, how will it work? When you’ll change the value of the Toggle using a control, the value of your New Date field will change according (we’ve played with dates here, but remember that this can be applied to loads of use cases. Also, to ensure to always have the same DATE format, we used a CAST: indeed, DATETIME_TRUNC returns DATETIME ^^).
So, what do we do next?
Build 2 dataviz, let’s say a table and a line chart, with our newly created New Date field as a dimension. Create a control based on our Toggle parameter.
And that’s pretty much it! Change the toggle value, and it will change the date dimension on all associated dataviz:
In this article, we’ve reviewed how to build a parameter to switch between day, week or month in Looker Studio.
PROBLEM SOLVED
Tools we use and we like:
Todoist: for tasks management
Monday: for projects management, when tasks fall short
Tropical Server: our friends in charge of the hosting of this very website!
Tools we’d like to use (if we had the budget…):