Skip to main content

Variance Model

How gold_variance_analysis and its variants compute actual vs budget. Source: dbt_project/models/gold/gold_variance_analysis.sql, gold_variance_ytd.sql, gold_variance_quarterly.sql, gold_variance_at_hierarchy_node.sql (konsolidat#206, PR #211, #220).

Inputs​

  • gold_scenario_trial_balance — one stream of (scenario, entity, year, period, account, budget dims, amount).
  • epm_gold.scenario_definitions — konsol's Scenario doctype. The model reads scenario_type and is_active, never a scenario code.
  • silver_main_accounts — account_name, account_type_name, is_pnl for accounts that appear only in the budget.

Pairing actuals with budgets​

  1. actual_scenarios = active scenarios of type actual; budget_scenarios = active scenarios of type budget. Forecast and other types are ignored.
  2. Every active budget scenario gets its own set of rows, keyed by budget_scenario_id. The actuals are repeated against each budget scenario that has lines for the same (entity, fiscal year). Two budgets are never summed.
  3. An actual (entity, year) that no budget scenario covers comes out once with budget_scenario_id = '' and budget_amount = null.
  4. Conditional aggregation on one stream, not a full outer join: under join_use_nulls = 0 the unmatched side of a join fills '' and 0, which lost the entity and account of budget-only lines.

Columns of gold_variance_analysis​

ColumnFormula
actual_amountsumIf(amount, scenario_type = 'actual')
budget_amountsumIf(amount, scenario_type = 'budget'), or null when the grain has no budget line in this scenario
variance_absactual_amount - coalesce(budget_amount, 0)
variance_pct(actual_amount - budget_amount) / abs(budget_amount) * 100; null when budget is null or 0
variance_favorablesee below
is_pnlfrom silver_main_accounts, 0 if unknown
budget_scenario_idthe budget scenario this row compares against

Favourable direction​

budget_amount is null → false
is_pnl = 0 → false
account_type_name = 'Revenue' → actual_amount > budget_amount
account_type_name = 'Expense' → actual_amount < budget_amount
anything else → false

account_type_name is the konsol group chart's vocabulary (konsol#182). The generic Profit and loss type has no favourable direction by design. There is no materiality floor in the variance models; materiality_floor() (0.005, konsolidat#209) is used by posting and reconciliation models, not here.

Variants​

ModelPeriod columnMeasuresNotes
gold_variance_ytdfiscal_periodytd_actual, ytd_budget, ytd_variance_abs, ytd_variance_pctRunning sums within (entity, year, account, dims, budget_scenario_id). ytd_budget is null until the first budget line of the year.
gold_variance_quarterlyfiscal_quarter (via gold_period_hierarchy)actual_amount, budget_amount, variance_abs, variance_pctNo favourable flag.
gold_variance_at_hierarchy_nodefiscal_periodactual_amount, budget_amount, variance_absRolls gold_variance_analysis up to reporting-hierarchy nodes, per budget_scenario_id, with the tree resolved at each period's end date (konsolidat#220). The rolled-up dimension is blanked.

Year-over-year is a separate model, gold_prior_year_comparison, built from gold_trial_balance alone: current_amount, prior_year_amount, yoy_variance_abs, yoy_variance_pct = (current - prior) / abs(prior) * 100.

Tests​

TestAssertion
assert_variance_abs_formulavariance_abs = actual_amount - budget_amount within 0.01 where budget is not null
assert_favorable_revenueis_pnl = 1, Revenue, actual > budget, budget not null → variance_favorable is true
assert_favorable_expenseis_pnl = 1, Expense, actual < budget, budget not null → true
assert_variance_budget_matches_yearNo row pairs a budget scenario with an (entity, year) it does not budget; uncovered grains appear once under '' — checked on all three flat models
assert_variance_covers_budget_scenariosEvery active budget scenario with rows has variance rows, and carries every actual grain exactly once with the right amount
assert_variance_node_single_budgetNode sums tie to gold_variance_analysis per budget_scenario_id; two budgets are never added
assert_scenario_rows_declaredEvery scenario in the scenario TB is declared, active and of the type its source allows

Excel​

Dataset variance_analysis reads gold_variance_analysis with default measure variance_abs. scenarioId filters on budget_scenario_id, so a site with two active budget scenarios picks one per cell.

Out of scope today​

  • Waterfall / bridge analysis (price, volume, mix)
  • Forecast vs budget or any two-scenario comparison other than declared actual vs each declared budget
  • Commentary on variances