Royal Civic Teal admin experience
Operational control surface
?
...
unknown
Model catalogue
/
Admin / dbt Studio / Models
kpi_cascade_snapshot
Open in Studio
SJ
Stale
last run 2025-07-01 02:00
· 17,765 rows
Compile
Test
Run
SQL
Compiled
Lineage
Docs
Preview
models/gold/kpi_cascade_snapshot.sql
Copy
{{ config( materialized='incremental', unique_key='kpi_period_sk', schema='gold' ) }} with actuals as ( select * from {{ ref('int_kpi_actuals') }} ), districts as ( select * from {{ ref('stg_districts') }} ) select md5(d.district_id::text || a.period) as kpi_period_sk, d.district_name, d.region, a.period, a.kpi_code, a.actual_value, a.target_value, round( a.actual_value / nullif(a.target_value, 0) * 100, 1 ) as attainment_pct, case when a.actual_value >= a.target_value then 'meeting' when a.actual_value >= a.target_value * 0.9 then 'approaching' else 'breach' end as kpi_status, current_timestamp as _materialized_at from actuals a join districts d on d.district_id = a.district_id {% if is_incremental() %} where a.period >= (select max(period) from {{ this }}) {% endif %}
Console
Clear
-- kpi_cascade_snapshot · open in dbt Studio