How to sort by rolling month

Knowledge Drop

Last tested: Oct 4, 2019
 

To sort their data by current month for ex: October 2019 thru November 2018, you can throw this in the lookml (dialect specific may be required):
 

dimension: this_month_num {

   hidden: yes

  sql: MONTH(CURDATE());;

 }    

dimension: sort_relative_month {

   type: number

   sql: CASE

         WHEN (${this_month_num} - ${created_date.month_num}) = 0

         THEN 12

         WHEN (${this_month_num} - ${created_date.month_num}) < 0

         THEN 12 - -1*(${this_month_num} - ${created_date.month_num})

         ELSE ${this_month_num} - ${created_date.month_num}

         END;;

 }

This content is subject to limited support.                

Comments
Salemchilis
Observer
247afb4a-62f1-49a0-b9eb-3defb75e6502.jpg

Salemlocal

Version history
Last update:
‎07-07-2021 12:41 PM
Updated by: