Dynamic dimension based on date filter

Hey guys,
I am currently trying to create a dynamic dimension based on the value of a filter. Simple you would say. But what if the filter is date type and I would like to make the dimension dependent on the timeframe (time granularity) the user picks from the date filter

Here is what a small example that does NOT work:

  filter: my_date_filter {
    description: "This is my date filter"
    type: date_time
  }
  
  dimension: display_time_range {
    label: "Display time range"
    can_filter: no
    sql:
      {% if my_date_filter.timeframe == 'week' %}
          ${TABLE}.week
      {% elsif my_date_filter.timeframe == 'month' %}
          ${TABLE}.month
      {% else %}
        ${TABLE}.day
      {% endif %};;
  }

Any ideas?
Thank you

1 2 642
2 REPLIES 2
Top Labels in this Space
Top Solution Authors