Skip to content

Commit 6d452b9

Browse files
committed
Introduce new quarterly model
1 parent b5c3f8b commit 6d452b9

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

dbt-models/models/food_bank_report/food_bank_report.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ models:
4747
Quarterly report on the distribution of the number of family members
4848
among the unique number of families visiting over the period.
4949
50+
- name: viz_food_bank_report__supply_sources__quarterly
51+
description: >
52+
Quarterly report including stock metrics related to product entries
53+
from the various supply sources.
54+
5055
exposures:
5156
- name: food-bank-report
5257
description: >-
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
with supply_source as (
2+
3+
select * from {{ ref('viz_operations__stock_entries_sources') }}
4+
5+
),
6+
7+
visit_events as (
8+
9+
select * from {{ ref('stg_families__visit_events') }}
10+
11+
),
12+
13+
quarters_calendar as (
14+
15+
select
16+
date_trunc('quarter', visit_date)::date as quarter_at
17+
from visit_events
18+
group by 1
19+
20+
),
21+
22+
distinct_supply_source as (
23+
24+
select
25+
source_name
26+
from supply_source
27+
group by 1
28+
29+
),
30+
31+
quarter_sources_cross_join as (
32+
33+
select
34+
quarters_calendar.quarter_at,
35+
distinct_supply_source.source_name
36+
from quarters_calendar
37+
cross join distinct_supply_source
38+
39+
),
40+
41+
supply_sources_aggregate as (
42+
43+
select
44+
date_trunc('quarter', date_at)::date as quarter_at,
45+
source_name,
46+
sum(batch_quantity) as batch_quantity,
47+
sum(monetary_value_eur) as monetary_value_eur
48+
from supply_source
49+
group by 1,2
50+
51+
),
52+
53+
final as (
54+
55+
select
56+
quarter_sources_cross_join.quarter_at,
57+
quarter_sources_cross_join.source_name,
58+
coalesce(supply_sources_aggregate.batch_quantity, 0::numeric) as batch_quantity,
59+
coalesce(supply_sources_aggregate.monetary_value_eur, 0) as monetary_value_eur
60+
from quarter_sources_cross_join
61+
left join supply_sources_aggregate
62+
on quarter_sources_cross_join.quarter_at = supply_sources_aggregate.quarter_at
63+
64+
)
65+
66+
select * from final

dbt-models/models/schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ models:
128128
columns:
129129
- name: date_at
130130
description: The date when the operation occurred
131-
- name: source
131+
- name: source_name
132132
description: >
133133
The acquisition channel for this operation.
134134
Either 'Pleins Courses', 'Collectes Supermarché' or 'Enlèvements BAPIF'

0 commit comments

Comments
 (0)