用量
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。這樣一來,您的使用者就能使用自訂日曆維度時間範圍建立「探索」查詢。
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
如要建立使用自訂日曆的年對年 (YoY) 評估指標,您也必須在 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 的時間範圍子參數為必填欄位。如果特定時間範圍 (例如 custom_season) 與自訂日曆無關,您仍須在日曆檢視畫面中定義預留位置維度,將該時間範圍納入其中。例如:
dimension: season {
type: string
sql: 'N/A' ;;
hidden: yes
}
dimension: season_num {
type: number
sql: 0 ;;
hidden: yes
}
範例
以下是名為 fiscal_calendar.view.lkml 的檢視表檔案範例,可模擬名為 fiscal_calendar_table 的自訂日曆資料表:
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
}
}