How to sort starting with the current month

When we sort chronologically - it starts with January - December

How can we sort so that the first row is always the current month, like in this screenshot:

We can sort on a table calculation (which we will hide from the visualization so it doesn’t get plotted)

If the month column’s value > current month (ex. Row 2, August > July evaluates to true)
we’d take the month_num and subtract the current month value (8 - 7)
If not, we would add them (ex. Row 9, March > July evaluates to false, we’ll take 3 + 7)

The table calc syntax looks something like this:

if(
  ${orders.order_month_num} >= extract_months(now()),
  ${orders.order_month_num} - extract_months(now()), 
  ${orders.order_month_num} + extract_months(now()) 
)

1 Like