calendar_definition

用途

view: retail_custom_calendar {
  calendar_definition: {
    reference_date: ref_date
    timeframe_mapping: {
      custom_date: custom_date
      custom_period: custom_period
      custom_quarter: custom_quarter
      custom_season: custom_season
      custom_week: custom_week
      custom_year: custom_year
    }
    timeframe_ordinal_mapping: {
      custom_date: custom_date
      custom_period: custom_period
      custom_quarter: custom_quarter
      custom_season: custom_season
      custom_week: custom_week
      custom_year: custom_year
    }
    previous_ordinal_mapping: {
      custom_date: custom_date
      custom_week: custom_week
    }
  }
階層
calendar_definition

定義

Looker でカスタム カレンダーを使用する際に、calendar_definition パラメータを使用すると、Looker のカスタム カレンダーの時間枠を、データベースで作成したカスタム カレンダー テーブルの列にマッピングできます。

カスタム カレンダー ビュー ファイルの設定については、Looker でカスタム カレンダーを使用するのドキュメント ページをご覧ください。

カスタム カレンダーのビューファイルに calendar_definition パラメータ ブロックを追加します。次に例を示します。

  calendar_definition: {
    reference_date: ref_date
    timeframe_mapping: {
      custom_date: custom_date
      custom_period: custom_period
      custom_quarter: custom_quarter
      custom_season: custom_season
      custom_week: custom_week
      custom_year: custom_year
    }
    timeframe_ordinal_mapping: {
      custom_date: ordinal_custom_date
      custom_period: ordinal_custom_period
      custom_quarter: ordinal_custom_quarter
      custom_season: ordinal_custom_season
      custom_week: ordinal_custom_week
      custom_year: ordinal_custom_year
    }
    previous_ordinal_mapping: {
      custom_date: prev_day_num
      custom_week: prev_week_num
    }
  }

calendar_definition パラメータ ブロックについては、次の点に注意してください。

  • reference_date パラメータは必須です。
  • timeframe_mapping パラメータと timeframe_ordinal_mapping パラメータ、およびそれらのすべてのサブパラメータは必須です。詳しくは、必須の期間をご覧ください。
  • previous_ordinal_mapping パラメータ ブロックは、前年同期比の指標を含むカスタム カレンダーで使用され、当週が 1 の場合に前週を処理する方法と、当日が 1 の場合に前日を処理する方法を Looker に伝えます。Looker 26.8 以降では、previous_ordinal_mapping パラメータは省略可能です。

このページの例のセクションをご覧ください。

LookML でカスタム カレンダー テーブルをモデリングしたら、カスタム カレンダー ビューに基づく type: custom_calendar のディメンショングループを作成できます。エンドユーザーは、カスタム カレンダー ディメンションの期間を使用して、Explore クエリを作成できます。

reference_date

reference_date パラメータは、カスタム カレンダー ビューのディメンションを指定します。このディメンションは、標準カレンダーの日付(2026-01-01 など)を提供するカスタム カレンダー データベース テーブルの列にマッピングされます。

reference_date パラメータについては、次の点に注意してください。

  • Looker は を使用して、データテーブルからカスタム カレンダー テーブルへの結合を計算し、カスタム期間を使用するクエリ結果を提供するため、reference_date は必須です。
  • reference_date は一意であるか、主キーである必要があります。

このページの例のセクションで、reference_date がカスタム カレンダー テーブルの列をモデル化するディメンションを指す方法を確認してください。

timeframe_mapping

timeframe_mapping ブロックは、各 Looker カスタム期間を、カスタム カレンダー データベース テーブルの同等の列をモデル化するディメンションにマッピングします。

timeframe_mapping: {
  custom_date: field-ref
  custom_period: field-ref
  custom_quarter: field-ref
  custom_season: field-ref
  custom_week: field-ref
  custom_year: field-ref
}

このページの例のセクションで、各 timeframe_mapping サブパラメータがカスタム カレンダー テーブルの列をモデル化するディメンションを指定する方法を確認してください。

timeframe_ordinal_mapping

timeframe_ordinal_mapping ブロックは、各 Looker カスタム期間を、カスタム カレンダー データベース テーブルの適切な順序列をモデル化するディメンションにマッピングします。

timeframe_ordinal_mapping: {
  custom_date: field-ref
  custom_period: field-ref
  custom_quarter: field-ref
  custom_season: field-ref
  custom_week: field-ref
  custom_year: field-ref
}

このページの例のセクションで、各 timeframe_ordinal_mapping サブパラメータがカスタム カレンダー テーブルの列をモデル化するディメンションを指定する方法を確認してください。

previous_ordinal_mapping

カスタム カレンダーを使用する前年同期比(PoP)の指標を作成する場合は、calendar_definition に previous_ordinal_mapping ブロックを追加することもできます。previous_ordinal_mapping ブロックは、custom_date と custom_week の Looker 期間を、前日と前週が指定されているカスタム カレンダー データベース テーブルの列をモデル化するディメンションにマッピングします。

previous_ordinal_mapping: {
  custom_date: field-ref
  custom_week: field-ref
}
  • custom_date パラメータは、当日が 1 日の場合に前日を処理する方法を Looker に指示します。
  • custom_week パラメータは、今週が 1 の場合に前週を処理する方法を Looker に指示します。

Looker 26.8 以降では、previous_ordinal_mapping パラメータは省略可能です。previous_ordinal_mapping ブロックを省略すると、Looker は 52 週の年を想定します。この場合、Week 1 の前の値は 52、Day 1 の前の値は 364 になります。

必須のタイムフレーム

timeframe_mapping と timeframe_ordinal_mapping の timeframes サブパラメータは必須です。custom_season などの特定の期間がカスタム カレンダーに関連しない場合でも、カレンダー ビューでプレースホルダ ディメンションを定義して、その期間を含める必要があります。次に例を示します。

 dimension: season {
    type: string
    sql: 'N/A' ;;
    hidden: yes
  }
  dimension: season_num {
    type: number
    sql: 0 ;;
    hidden: yes
  }

例

fiscal_calendar_table というカスタム カレンダー テーブルをモデル化する fiscal_calendar.view.lkml というビューファイルの例を次に示します。

view: fiscal_calendar {
  sql_table_name: fiscal_calendar_table ;;

  calendar_definition: {
    reference_date: reference_date

    timeframe_mapping: {
      custom_year: fiscal_year
      custom_quarter: fiscal_quarter_of_year
      custom_date: fiscal_date_of_month
      custom_week: fiscal_week_of_year
      custom_period: fiscal_period_of_year
      custom_season: season
    }
    timeframe_ordinal_mapping: {
      custom_year: fiscal_year_num
      custom_quarter: fiscal_quarter_of_year_num
      custom_date: fiscal_date_of_month_num
      custom_week: fiscal_week_of_year_num
      custom_period: fiscal_period_of_year_num
      custom_season: season_num
    }
    previous_ordinal_mapping: {
          custom_date: prev_custom_date
          custom_week: prev_custom_week
    }
  }

  dimension: reference_date {
    type: date
    primary_key: yes
    sql: ${TABLE}.reference_date ;; # Name of the column in your database table that shows the standard date, such as `2026-01-01`
  }

  dimension: fiscal_year {
    type: string
    sql: ${TABLE}.fiscal_year ;;
  }

  dimension: fiscal_year_num {
    type: number
    sql: ${TABLE}.fiscal_year_num ;;
  }

  dimension: prev_custom_week {
          type: number
          sql: ${TABLE}.prev_custom_week ;;
        }

  # ... other dimensions for quarters, weeks, periods, seasons, etc. ...

  # Example placeholder dimensions for unused timeframes
  dimension: season {
    type: string
    sql: 'N/A' ;;
    hidden: yes
  }
  dimension: season_num {
    type: number
    sql: 0 ;;
    hidden: yes
  }
}