Skip to main content

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).

TableWritten byGrain
epm_gold.budget_annual_inputBudget Annual Input doctype, on every savescenario, entity, year, account, budget dims → annual_amount, spread_profile_id
epm_gold.spread_profilesSpread Profile doctype, on every saveprofile_id, fiscal_period → weight
epm_gold.budget_monthly_inputBudget 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​

  1. annual_input — reads budget_annual_input, stamps layer = 'base'. Annual input predates layering and has no layer of its own.
  2. profiles — normalises weights: period_weight = weight / sum(weight) over (partition by profile_id).
  3. manual — reads budget_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_amount
    • period_amount = amount
    • spread_profile_id = 'manual', profile_name = 'Manual (as-entered)'
  4. spread — inner-joins annual_input to profiles on spread_profile_id = profile_id and computes period_amount = annual_amount × period_weight. An annual row whose profile does not exist produces nothing. Precedence: a spread row is dropped when manual has a base row at the same (scenario, entity, year, account, dims). Typed months override an annual spread; non-base manual layers are additive and never displace anything.
  5. 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​

ReaderHow 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_balanceSums period_amount over layers to one row per grain; the scenario TB is the final budget
gold_budget_at_hierarchy_nodeKeeps layer in the group-by so hierarchy reads can filter to one layer (konsol#63)

Tests​

TestAssertion
assert_spread_sums_to_annualΣ period_amount = annual_amount within 0.01 per (scenario, entity, year, account)
assert_spread_has_12_periodsAnnual-spread lines (spread_profile_id != 'manual') have exactly 12 distinct periods
assert_budget_fact_grain_uniqueOne row per (scenario, entity, year, period, account, dims)

Decisions recorded in the code​

DecisionReference
One canonical monthly budget fact for both entry methods; manual overrides annual at the same grainkonsolidat#94
Seeds deleted; both budget tables and the profiles are konsol'skonsolidat#146, #147
Layers carried as rows, summed at read timekonsol#63
A site with zero budget dimensions must still buildkonsolidat#220
Budget tables name no dimension; columns follow in_budget declarationskonsol#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