Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name columns in Looker based on the current month?

Tags:

looker

How to name columns in Looker based on the current month?

I have a dashboard which shows sales for the current month and past two months. I want these columns to be dynamically named for eg Sales_Sept, Sales_Aug and Sales_July. Depending on the month we are looking at the names should appear accordingly

like image 796
neha parekh Avatar asked Nov 23 '25 18:11

neha parekh


1 Answers

You can pivot by the month name column for dynamically named columns.

view: table_1 {
  derived_table: {
    sql: SELECT *
         FROM UNNEST(ARRAY<STRUCT<DATE DATE, A FLOAT64>>[
         ('2020-12-01', 10),
         ('2020-12-15', 30),
         ('2021-01-01', 30),
         ('2021-01-15', 60)])
       ;;
  }
  dimension_group: row {
    type: time
    datatype: date
    sql: ${TABLE}.date ;;
  }
  dimension: a {
    type: number
  }
  measure: total_a {
    type: sum
    sql: ${a} ;;
  }
}

explore: table_1 {}

Aggregate to month name:

Row totals for the last two months

Pivot by month name:

Row totals as named columns by month

like image 57
CSJCampbell Avatar answered Nov 28 '25 01:11

CSJCampbell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!