Looker Dashboard - Filters: Switch between monthly, weekly, daily views

Niki1
Participant I

Hello Community,

I am creating a looker dashboard, based on the -let’s say- last 5 days with a barchart of certain metrics per day, and would like to add a filter on the top of the dashboard to show me they last 5 weeks (or last 5 month etc.)
Is that possible to switch easily between days, month etc.?

Basically I would like to switch between daily charts to aggregated weekly and monthly views with only a click for the Enduser.

Thanks in advance for any reply!

Solved Solved
3 4 7,619
1 ACCEPTED SOLUTION

Dawid
Participant V

I believe what you’re asking for is Dynamic Granularity. Here is a doc from Looker’s help section to show you how it can be done:

https://help.looker.com/hc/en-us/articles/360001288468-Dynamic-Timeframes-for-Dimension-Groups

0bcfc6fb-b6d3-427b-a2de-d4898acc701d.png

View solution in original post

4 REPLIES 4

Dawid
Participant V

I believe what you’re asking for is Dynamic Granularity. Here is a doc from Looker’s help section to show you how it can be done:

https://help.looker.com/hc/en-us/articles/360001288468-Dynamic-Timeframes-for-Dimension-Groups

0bcfc6fb-b6d3-427b-a2de-d4898acc701d.png

Niki1
Participant I

That looks very interesting, thank you!

Niki1
Participant I

@Dawid Would I have to implement those types of parameters in every model then?


Then I could arrange a filter in my Dashboard, right?

Dawid
Participant V

We used to have them in every view but I think you could use something called a bare view (I think). 

I would have created it myself but I’m actually removing those granularities from our model (they’re not needed).

Anyway, test this:

  1. Create view “date_granularity.view.lkml”
  1. Do not include sql or sql_table name, just your parameter
  2. In your explore join the dates view
  3. reference the joined view

I do this with conversion currency like this:

3a2fe71f-421a-4c94-8ab0-7859dd1bec57.png

Then empty join

9d582554-fcad-4ab8-846e-898048195c59.png

And here is the example reference in a orders view

05f7eeed-cc06-4026-b47c-ba230a89da96.png

Like I mentioned, we used to copy the same code like this:



parameter: dates_granularity {
hidden: yes
type: unquoted
allowed_value: { label: "Date" value: "date" }
allowed_value: { label: "Week" value: "week" }
allowed_value: { label: "Month" value: "month" }
allowed_value: { label: "Quarter" value: "quarter" }
allowed_value: { label: "Year" value: "year" }
allowed_value: {label: "Raw" value:"raw"}
}

And then use it in dimension groups like this:


dimension_group: created_at {
type: time
timeframes: [raw, time, date, week, month, quarter, year, day_of_week, day_of_month]
sql: ${TABLE}.created_at ;;
}

dimension: order_created_at_granularity {
description: "Use it in conjunction with Dates Granularity Filter"
sql:
{% if dates_granularity._parameter_value == 'date' %} ${created_at_date}
{% elsif dates_granularity._parameter_value == 'week' %} ${created_at_week}
{% elsif dates_granularity._parameter_value == 'month' %} ${created_at_month}
{% elsif dates_granularity._parameter_value == 'quarter' %} ${created_at_quarter}
{% elsif dates_granularity._parameter_value == 'year' %} ${created_at_year}
{% elsif dates_granularity._parameter_value == 'raw' %} ${created_at_raw}
{% elsif dates_granularity._parameter_value == 'time' %} ${created_at_time}
{% else %} ${created_at_date}
{% endif %};;
}

But since I learned about this bare view approach, I would probably test it how much code I can put in one place before copying it in multiple places

Top Labels in this Space
Top Solution Authors