Budget Spreading
How gold_spread_budget turns konsol's two budget inputs into one monthly budget fact. Source: dbt_project/models/gold/gold_spread_budget.sql (konsolidat#94, #146, #220).
Inputs
All three are konsol write-throughs in epm_gold. The dbt project ships no seeds (konsolidat#147).
| Table | Written by | Grain |
|---|---|---|
epm_gold.budget_annual_input | Budget Annual Input doctype, on every save | scenario, entity, year, account, budget dims → annual_amount, spread_profile_id |
epm_gold.spread_profiles | Spread Profile doctype, on every save | profile_id, fiscal_period → weight |
epm_gold.budget_monthly_input | Budget Sheet, when its Budget Cycle locks (deleted again on cancel) | scenario, entity, year, account, budget dims, fiscal_period, layer → amount |
Budget dimensions come from get_budget_dimensions(): the Published Dimensions ticked in_budget. Neither table names a dimension in DDL (konsol#287).
The model, step by step
annual_input— readsbudget_annual_input, stampslayer = 'base'. Annual input predates layering and has no layer of its own.profiles— normalises weights:period_weight = weight / sum(weight) over (partition by profile_id).manual— readsbudget_monthly_input, all layers. Treated as an identity spread, so the row shape matches the annual branch:annual_amount = sum(amount) over (scenario, entity, year, account, dims, layer)period_weight = amount / annual_amountperiod_amount = amountspread_profile_id = 'manual',profile_name = 'Manual (as-entered)'
spread— inner-joinsannual_inputtoprofilesonspread_profile_id = profile_idand computesperiod_amount = annual_amount × period_weight. An annual row whose profile does not exist produces nothing. Precedence: aspreadrow is dropped whenmanualhas abaserow at the same (scenario, entity, year, account, dims). Typed months override an annual spread; non-base manual layers are additive and never displace anything.select * from spread union all select * from manual.
Output grain: one row per (scenario, entity, fiscal_year, fiscal_period, main_account, budget dims, layer). Columns: scenario_id, data_area_id, fiscal_year, fiscal_period, main_account, <dims>, layer, annual_amount, spread_profile_id, profile_name, period_weight, period_amount, submitted_by.
Readers
| Reader | How it uses layer |
|---|---|
konsol Dataset budget_input (=K.EPM_BUDGET, =K.EPM(…, "budget")) | has_layer = 1. No layer argument → sums all layers; with one → AND layer = … |
gold_scenario_trial_balance | Sums period_amount over layers to one row per grain; the scenario TB is the final budget |
gold_budget_at_hierarchy_node | Keeps layer in the group-by so hierarchy reads can filter to one layer (konsol#63) |
Tests
| Test | Assertion |
|---|---|
assert_spread_sums_to_annual | Σ period_amount = annual_amount within 0.01 per (scenario, entity, year, account) |
assert_spread_has_12_periods | Annual-spread lines (spread_profile_id != 'manual') have exactly 12 distinct periods |
assert_budget_fact_grain_unique | One row per (scenario, entity, year, period, account, dims) |
Decisions recorded in the code
| Decision | Reference |
|---|---|
| One canonical monthly budget fact for both entry methods; manual overrides annual at the same grain | konsolidat#94 |
| Seeds deleted; both budget tables and the profiles are konsol's | konsolidat#146, #147 |
| Layers carried as rows, summed at read time | konsol#63 |
| A site with zero budget dimensions must still build | konsolidat#220 |
Budget tables name no dimension; columns follow in_budget declarations | konsol#287 (budget fields: PR #343; Excel dimensions argument: PR #393) |
Out of scope today
- Driver-based planning (volume × price)
- Rolling forecast auto-spread
- Spreading at account-group level