Skip to main content

Adding Dimensions

A dimension is declared once, in konsol's Dimension doctype, and propagates through every model via Jinja macros. dbt never defines a dimension itself: the dimensions var in dbt_project.yml is generated.

How It Works​

1. konsol writes the registry into dbt_project.yml​

Publishing a Dimension regenerates the block between # --- BEGIN konsol-managed vars and # --- END konsol-managed vars in dbt_project.yml (konsol.dbt_config.regenerate_vars()), and applies the matching ClickHouse DDL (a dim_* column on the budget input tables and on epm_raw.trial_balance_submissions, konsol#287). The demo site's block:

vars:
dimensions:
- name: dim_business_unit
source_column: dim_business_unit
label: Business Unit
cube_type: string
in_budget: false
- name: dim_cost_center
source_column: dim_cost_center
label: Cost Center
cube_type: string
in_budget: true
- name: dim_department
source_column: dim_department
label: Department
cube_type: string
in_budget: true

A site may declare no dimensions (konsol#230); every macro then renders nothing, and the models still compile (konsolidat#220).

2. The macros read the var​

dimension_helpers.sql reads var('dimensions') and generates SQL fragments:

select
data_area_id,
{{ dim_select(trailing=true) }} -- dim_cost_center, dim_department, dim_business_unit,
{{ measure_select() }}
from {{ ref('silver_gl_entries') }}
group by
data_area_id{{ dim_group_by(leading=true) }}

3. Where the values come from​

  • ERP connectors: the staging adapter maps the ERP's field to the canonical dim_* column (stg_erpnext__gl_entries: cost_center → dim_cost_center, project → dim_business_unit), and stg_gl_entries harmonises the raw values through konsol's Dimension Mapping crosswalk (dim_harmonize_select / dim_harmonize_joins). Unmapped values pass through and show up in gold_unmapped_dimension_values.
  • Trial-balance upload: the submitted file's own dimension columns, read by bronze_trial_balance_submissions (konsol#255) and carried through silver_tb_movements into silver_gl_entries.

4. The API filters automatically​

The Dataset registry (Dataset Dimension rows) decides which dimensions a =K.EPM() call may filter on; the query builder adds them to the WHERE clause.

Adding a New Dimension​

  1. In konsol, create the Dimension (name dim_<x>, label, in_budget) and publish it. konsol regenerates the var block and applies the DDL.
  2. If an ERP connector feeds the site, add the source field to its staging adapter (models/staging/<erp>/stg_<erp>__gl_entries.sql) and, for budgets, stg_<erp>__budget_entries.sql. Note: with erp_sources non-empty, the canonical models' unioned CTE still names the three demo dimensions as literals (see the comment in gold_unmapped_dimension_values.sql); konsolidat#221 is removing ERP staging wholesale rather than widening it.
  3. Add Dimension Mapping rows for the ERP's raw values if they need harmonising.
  4. Rebuild: dbt build --full-refresh (the incremental models append positionally; a new column needs a full refresh).
  5. Add the dimension to the Datasets that should expose it.

Dimension Properties​

PropertyRequiredDescription
nameYesColumn name in the models (convention dim_*)
source_columnYesColumn dim_select_from_source() casts from in bronze. For the canonical staging path it equals name
labelYesDisplay name
cube_typeYesAnalytical type (currently string)
in_budgetYestrue to include in the budget models (get_budget_dimensions())

Which Macros Use Dimensions​

MacroWhere usedEffect
dim_select()SELECT listsAdds the dimension columns
dim_group_by()GROUP BYGroups by them
dim_join_on()JOIN conditionsMatches them across tables
dim_coalesce()FULL OUTER JOIN resultsPicks the non-null value
dim_partition_by()Window functionsPartitions by them
dim_empty_strings()Non-entity consolidation layers'' for IC, CTA, topside, deal rows
dim_select_from_source()BronzeCasts source_column to name
dim_harmonize_select(), dim_harmonize_joins()Canonical stagingCrosswalk through Dimension Mapping
tb_dimension_long_sql() and friendsHierarchy roll-upsUnpivot one row per dimension

All list macros accept trailing=true / leading=true so the comma appears only when the list is non-empty. See Macro Reference.

Budget Dimensions​

get_budget_dimensions() returns the dimensions with in_budget: true. Only those exist on gold_spread_budget, gold_scenario_trial_balance, the variance models and the budget input tables. On the demo: dim_cost_center and dim_department; dim_business_unit is excluded.

Dimensions and the year-end close​

The year-end close silver_tb_movements synthesizes moves the year's result into retained earnings as one lump on the blank dimension key (decision of 23 Sep 2026, Deepak Pai, konsol#255). A per-dimension close (Dimension.survives_close on) is not built.

Next Steps​