# Description This is a extremely simple but rather important PR. It just sets the cutoff for KPIs reporting to April 2022. This affects 1) Main KPIs, 2) Guest KPIs and 3) Account Managers report Motivation behind this is to have accurate data. Early 2022 might still be shitty, but at least we have a source of truth to compare against (on revenue side, finance P&L) I set a dedicated variable because currency rates is reading from the same start date, and I intend only to modify KPIs cutoff. # Checklist - [X] The edited models and dependants run properly with production data. - [NA] The edited models are sufficiently documented. - [NA] The edited models contain PK tests, and I've ran and passed them. - [NA] I have checked for DRY opportunities with other models and docs. - [NA] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. **I need to manually run a full-refresh on daily listing segmentation that is incremental** Adds dedicated start date for KPIs Related work items: #26712
59 lines
1.8 KiB
SQL
59 lines
1.8 KiB
SQL
{{ config(materialized="table", unique_key="date") }}
|
|
|
|
with
|
|
int_dates as (
|
|
select *
|
|
from {{ ref("int_dates") }}
|
|
where date_day >= {{ var("kpis_start_date") }}
|
|
),
|
|
raw_dates as (
|
|
select
|
|
id.year_number as year,
|
|
id.month_of_year as month,
|
|
id.iso_week_of_year as week,
|
|
id.day_of_month as day,
|
|
id.date_day as date,
|
|
id.month_start_date as first_day_month,
|
|
id.month_end_date as last_day_month,
|
|
id.iso_week_start_date as first_day_week,
|
|
id.iso_week_end_date as last_day_week,
|
|
now()::date as today
|
|
from int_dates id
|
|
)
|
|
select distinct
|
|
rd.year,
|
|
rd.month,
|
|
rd.week,
|
|
rd.day,
|
|
rd.date,
|
|
rd.first_day_month,
|
|
rd.last_day_month,
|
|
case when rd.date = rd.last_day_month then true else false end as is_end_of_month,
|
|
case
|
|
when date_trunc('month', rd.date) = date_trunc('month', rd.today)
|
|
then true
|
|
else false
|
|
end as is_current_month,
|
|
case
|
|
when date_trunc('month', rd.date) = date_trunc('month', rd.today)
|
|
then true
|
|
when
|
|
rd.year = extract(year from rd.today) - 1
|
|
and rd.month = extract(month from rd.today)
|
|
and rd.day < extract(day from rd.today)
|
|
then true
|
|
else false
|
|
end as is_month_to_date,
|
|
rd.first_day_week,
|
|
rd.last_day_week,
|
|
case when rd.date = rd.last_day_week then true else false end as is_end_of_week,
|
|
case
|
|
when date_trunc('week', rd.date) = date_trunc('week', rd.today)
|
|
then true
|
|
else false
|
|
end as is_current_week,
|
|
case when rd.today - rd.date = 1 then true else false end as is_yesterday
|
|
from raw_dates rd
|
|
where
|
|
-- include only up-to yesterday
|
|
rd.today > rd.date
|