Merged PR 3563: Add week number to model

# Description

Added week number to model in order to better display granularity in the report and Power BI doesn't correctly compute the week number of dates

# Checklist

- [x] The edited models and dependants run properly with production data.
- [x] The edited models are sufficiently documented.
- [x] The edited models contain PK tests, and I've ran and passed them.
- [ ] I have checked for DRY opportunities with other models and docs.
- [ ] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Add week number to model

Related work items: #23998
This commit is contained in:
Joaquin Ossa 2024-11-18 11:01:22 +00:00
commit 30a12f6875
5 changed files with 31 additions and 2 deletions

View file

@ -3,7 +3,15 @@ with
select distinct has_payment, has_id_check select distinct has_payment, has_id_check
from {{ ref("int_kpis__metric_daily_check_in_attributed_guest_journeys") }} from {{ ref("int_kpis__metric_daily_check_in_attributed_guest_journeys") }}
) )
select d.date_day, ud.has_payment, ud.has_id_check select
d.date_day,
case
when d.iso_week_of_year < 10
then concat('Week-0', d.iso_week_of_year)
else concat('Week-', d.iso_week_of_year)
end as date_week,
ud.has_payment,
ud.has_id_check
from {{ ref("int_dates") }} as d from {{ ref("int_dates") }} as d
cross join unique_dimensions as ud cross join unique_dimensions as ud
where d.date_day >= {{ var("start_date") }} where d.date_day >= {{ var("start_date") }}

View file

@ -44,6 +44,7 @@ with
guest_kpis as ( guest_kpis as (
select select
dd.date_day, dd.date_day,
dd.date_week,
dd.has_payment, dd.has_payment,
dd.has_id_check, dd.has_id_check,
gj.created_guest_journeys_not_cancelled, gj.created_guest_journeys_not_cancelled,
@ -76,6 +77,7 @@ with
select select
gk.date_day, gk.date_day,
gk.date_week,
gk_py.date_day as py_date_day, gk_py.date_day as py_date_day,
gk.has_payment, gk.has_payment,
gk.has_id_check, gk.has_id_check,
@ -135,4 +137,4 @@ left join
and gk.has_id_check = gk_py.has_id_check and gk.has_id_check = gk_py.has_id_check
-- Here we use a group by because of leap days that generate duplicity when being -- Here we use a group by because of leap days that generate duplicity when being
-- moved to another year -- moved to another year
group by gk.date_day, gk_py.date_day, gk.has_payment, gk.has_id_check group by gk.date_day, gk.date_week, gk_py.date_day, gk.has_payment, gk.has_id_check

View file

@ -5885,6 +5885,12 @@ models:
tests: tests:
- not_null - not_null
- name: date_week
data_type: string
description: "Week number of when Guest Journeys have been completed."
tests:
- not_null
- name: has_payment - name: has_payment
data_type: string data_type: string
description: Has there been any guest payments on the guest journey. description: Has there been any guest payments on the guest journey.
@ -5933,6 +5939,12 @@ models:
tests: tests:
- not_null - not_null
- name: date_week
data_type: string
description: "Week number of when Guest Journeys have been completed."
tests:
- not_null
- name: py_date_day - name: py_date_day
data_type: date data_type: date
description: | description: |

View file

@ -5,6 +5,7 @@ with
select select
date_day as date_day, date_day as date_day,
date_week as date_week,
py_date_day as py_date_day, py_date_day as py_date_day,
has_payment as has_payment, has_payment as has_payment,
has_id_check as has_id_check, has_id_check as has_id_check,

View file

@ -28,6 +28,12 @@ models:
tests: tests:
- not_null - not_null
- name: date_week
data_type: string
description: "Week number of when Guest Journeys have been completed."
tests:
- not_null
- name: py_date_day - name: py_date_day
data_type: date data_type: date
description: | description: |