Looker starts the week on Monday. For example, if today is Thursday, April 11, 2019, today belongs to the week 04/08/2019. If it is Saturday, April 20, 2019, today belongs in the week 04/15/2019.
However, some reports must display week-ending dates rather than week-beginning dates. How do you get Looker to display the ending dates for weeks? You can convert the dates to an end date on Sundays.
Example
- We start with the
created
dimension group. - In the next dimension, we add 7 days to end the week on Sunday. This is how it looks in LookML:
dimension_group: created {
type: time
timeframes: [time, hour_of_day, date, week, month, year]
sql: ${TABLE}.created ;;
}
dimension: created_week_ending_sunday {
type: date
sql: DATEADD( day, 7, ${created_date});;
datatype: date
}
The example above uses theDATEADD
function from Redshift. TheDATEADD
function may differ on other SQL dialects.
You can use this method to end days on whichever day of the week you like. If you want to modify the day of the week that your weeks begin, you can use the week_start_day
LookML parameter, as described on this documentation page.