Last tested: Dec 2, 2019
Currently, there are no week-related table calculation functions available. Below are feature requests and workarounds for various week-related functions.
A function to extract the day of the week or day of week index from a date field doesn't currently exist - request it here.
day_of_week_indexmod(diff_days(date(2008,01,01), ${orders.created_date}) + 1, 7)
day_of_weekindex( list("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), mod(diff_days(date(2008,01,01), ${orders.created_date}) + 1, 7))
A function to get the week from a date field doesn't currently exist
add_days(-1 * mod(diff_days(date(2008,01,01), ${orders.created_date}) + 1, 7), ${orders.created_date})
No function currently available natively, request it here.
diff_days(${start_date}, ${end_date}) + 3 - floor(diff_days(add_days(-1 * (mod(diff_days(date(2008,01,01), add_days(-6, ${start_date})) + 1, 7)), add_days(-6, ${start_date})), add_days(-1 * (mod(diff_days(date(2008,01,01), add_days(2, ${end_date})) + 1, 7)), add_days(2, ${end_date})))/7) - floor(diff_days(add_days(-1 * (mod(diff_days(date(2008,01,01), add_days(-7, ${start_date})) + 1, 7)), add_days(-7, ${start_date})), add_days(-1 * (mod(diff_days(date(2008,01,01), add_days(1, ${end_date})) + 1, 7)), add_days(1, ${end_date})))/7)
This content is subject to limited support.
Keep in mind we can create the start_date and end_date with the min/max date columns table calcs here as well:
It feels like an odd omission to not have week-based Looker functions. Our company relies heavily on weekly reporting, and so including something like trunc_week would be super useful.
I tried to follow the “request it here” links, but I keep getting sent to a Pendo log-in page for which I have no credentials and cannot create an account. A bit frustrating ?