用途
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パラメータ ブロックは、期間比較の指標でカスタム カレンダーを使用する場合にのみ必要です。
このページの例のセクションをご覧ください。
LookML でカスタム カレンダー テーブルをモデリングしたら、カスタム カレンダー ビューに基づいて type: custom_calendar のディメンション グループを作成できます。エンドユーザーは、カスタム カレンダー ディメンションの期間を使用して Explore クエリを作成できます。
reference_date
reference_date パラメータは、カスタム カレンダー ビューのディメンションを指定します。このディメンションは、標準のカレンダー日付(2026-01-01 など)を提供するカスタム カレンダー データベース テーブルの列にマッピングされます。
reference_date パラメータについては、次の点に注意してください。
- Looker は
reference_dateを使用して、データテーブルからカスタム カレンダー テーブルへの結合を計算し、カスタム期間を使用するクエリ結果を提供するため、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 ブロックは、各 Looker カスタム期間を、カスタム カレンダー データベース テーブルの適切な列をモデル化するディメンションにマッピングします。
previous_ordinal_mapping: {
custom_date: field-ref
custom_week: field-ref
}
このページの例のセクションで、各 previous_ordinal_mapping サブパラメータがカスタム カレンダー テーブルの列をモデル化するディメンションを指定する方法を確認してください。
必須のタイムフレーム
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
}
}