Solved

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

  • 23 February 2021
  • 4 replies
  • 54 views

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!

icon

Best answer by Dawid_Nawrot 23 February 2021, 12:38

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

 

View original

4 replies

Userlevel 6
Badge

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

 

That looks very interesting, thank you!

 

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


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

Userlevel 6
Badge

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:

Then empty join

And here is the example reference in a orders view

 

 

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

Reply