用途
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 に指示します。previous_ordinal_mappingパラメータは、Looker 26.8 以降では省略可能です。
このページの例のセクションをご覧ください。
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)指標を作成する場合は、previous_ordinal_mapping ブロックを calendar_definition に追加することもできます。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 に指示します。
previous_ordinal_mapping パラメータは、Looker 26.8 以降では省略可能です。previous_ordinal_mapping ブロックが省略されている場合、Looker は 52 週の年を想定します。この場合、1 週目の前の値は 52、1 日目の前の値は 364 になります。
必須の期間
timeframe_mapping と timeframe_ordinal_mapping の期間サブパラメータは必須です。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
}
}