This is part of my “current_time” or “time_comparisons” view:
view: current_time {
dimension_group: current {
type: time
sql: CURRENT_TIMESTAMP ;;
timeframes: [date, hour_of_day, minute, day_of_week, day_of_month, day_of_year, week_of_year, day_of_week_index, time_of_day, month, month_name, month_num, time, week, year, raw]
}
dimension: second_of_day {
group_label: "Current"
type: number
sql: (EXTRACT(HOUR FROM CURRENT_TIMESTAMP) * 60 * 60) + (EXTRACT(MINUTE FROM CURRENT_TIMESTAMP) * 60) + EXTRACT(SECOND FROM CURRENT_TIMESTAMP) ;;
}
}
In my data explore I join it like this
join: current_time {
fields: []
relationship: one_to_one
sql: ;;
}
Then I added a refinement only for one field - my date/timetamp/datetime where I create the boolean fields
view: +my_view{
dimension_group: timestamp_expanded {
sql: CAST(${TABLE}.timestampAS TIMESTAMP);;
type: time
hidden: yes
timeframes: [date, week, month, quarter, time_of_day, hour_of_day, time, raw, day_of_week, day_of_week_index, day_of_month, day_of_year]
}
dimension: second_of_day {
hidden: yes
group_label: "Second of"
group_item_label: "Day"
type: number
sql: ${timestamp_expanded_hour_of_day} * 60 * 60 + 3600;;
}
dimension: is_before_now_day {
group_label: "Before Current Time of"
group_item_label: "Day"
type: yesno
sql: ${second_of_day} <= ${current_time.second_of_day} ;;
}
}
The view above calculates the second of each timeframe for timestamps coming from data. The Current Time gives me a second for each timeframe of this point in time.. Then I just compare. Using this with either filters “last 12 months” or calendar table should give you what you want.