Skip to content

Instantly share code, notes, and snippets.

@richkuz
Last active November 9, 2024 13:09
Show Gist options
  • Save richkuz/38d0d6a40e004f4135b2068a001bf53c to your computer and use it in GitHub Desktop.
Save richkuz/38d0d6a40e004f4135b2068a001bf53c to your computer and use it in GitHub Desktop.
Compute max date time in a Looker calculation expression

In a Looker table calculation custom expression you can compute the max or min value of a date time object using an expression like this:

max(
  (100 * 100 * 100 * 100 * 100 * extract_years(${table.created_at})) +
  (100 * 100 * 100 * 100 * extract_months(${table.created_at})) +
  (100 * 100 * 100 * extract_days(${table.created_at})) +
  (100 * 100 * extract_hours(${table.created_at})) +
  (100 * extract_minutes(${table.created_at})) +
  (extract_seconds(${table.created_at}))
)

Looker doesn't let you perform a min or a max on a date object directly, you have to convert it to a number like this first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment