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 readsscenario_typeandis_active, never a scenario code.silver_main_accounts—account_name,account_type_name,is_pnlfor accounts that appear only in the budget.
Pairing actuals with budgets
actual_scenarios= active scenarios of typeactual;budget_scenarios= active scenarios of typebudget. Forecast and other types are ignored.- 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. - An actual (entity, year) that no budget scenario covers comes out once with
budget_scenario_id = ''andbudget_amount = null. - Conditional aggregation on one stream, not a full outer join: under
join_use_nulls = 0the unmatched side of a join fills''and0, which lost the entity and account of budget-only lines.
Columns of gold_variance_analysis
| Column | Formula |
|---|---|
actual_amount | sumIf(amount, scenario_type = 'actual') |
budget_amount | sumIf(amount, scenario_type = 'budget'), or null when the grain has no budget line in this scenario |
variance_abs | actual_amount - coalesce(budget_amount, 0) |
variance_pct | (actual_amount - budget_amount) / abs(budget_amount) * 100; null when budget is null or 0 |
variance_favorable | see below |
is_pnl | from silver_main_accounts, 0 if unknown |
budget_scenario_id | the 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
| Model | Period column | Measures | Notes |
|---|---|---|---|
gold_variance_ytd | fiscal_period | ytd_actual, ytd_budget, ytd_variance_abs, ytd_variance_pct | Running sums within (entity, year, account, dims, budget_scenario_id). ytd_budget is null until the first budget line of the year. |
gold_variance_quarterly | fiscal_quarter (via gold_period_hierarchy) | actual_amount, budget_amount, variance_abs, variance_pct | No favourable flag. |
gold_variance_at_hierarchy_node | fiscal_period | actual_amount, budget_amount, variance_abs | Rolls 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
| Test | Assertion |
|---|---|
assert_variance_abs_formula | variance_abs = actual_amount - budget_amount within 0.01 where budget is not null |
assert_favorable_revenue | is_pnl = 1, Revenue, actual > budget, budget not null → variance_favorable is true |
assert_favorable_expense | is_pnl = 1, Expense, actual < budget, budget not null → true |
assert_variance_budget_matches_year | No 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_scenarios | Every active budget scenario with rows has variance rows, and carries every actual grain exactly once with the right amount |
assert_variance_node_single_budget | Node sums tie to gold_variance_analysis per budget_scenario_id; two budgets are never added |
assert_scenario_rows_declared | Every 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