Dimension switch table reference

Dimension switch table examples

Contents: Use cases, Chart IDs, Minimal spec, Data, Options, Annotations, What the table is for, Mental model, Host data: what to supply and how to compute it, Measures: values, formats, changes and judgment, Statements: subtotals, results and drivers, View options, Worked example, React usage, Common mistakes, Sizing, Fixtures, Not for.

A KPI table: measures by one hierarchical dimension by period, switchable between KPI rows over members and member rows over KPIs. The host supplies additive sums per member and period; boardplot derives ratios, changes and judgment. Type dimswitch. Aliases: dim-switch-table, dim-switch.

Use cases

Chart IDs

Minimal spec

{
  "type": "dimswitch",
  "data": {
    "dimension": {
      "label": "Channel",
      "total": { "id": "total", "label": "Total" },
      "headline": ["orders", "cac"],
      "members": [{ "id": "paid", "label": "Paid Search" }, { "id": "organic", "label": "Organic" }]
    },
    "measures": [
      {
        "id": "orders",
        "label": "Orders",
        "scale": "count",
        "value": { "field": "orders" },
        "judge": { "family": "volume", "base": "orders" }
      },
      {
        "id": "new",
        "label": "New customers",
        "scale": "count",
        "parentId": "orders",
        "value": { "field": "nc" }
      },
      {
        "id": "cac",
        "label": "CAC",
        "scale": "perUnit",
        "value": { "op": "div", "a": { "field": "spend" }, "b": { "field": "nc" } },
        "format": "$1.2",
        "unit": "$",
        "judge": { "family": "cost", "base": "nc" }
      }
    ],
    "periods": [
      { "id": "range", "label": "Current period", "kind": "range" },
      { "id": "prior", "label": "Prior period", "kind": "prior" },
      { "id": "w1", "label": "Week 1" }
    ],
    "facts": [
      {
        "memberId": "total",
        "periodId": "range",
        "sums": { "orders": 120, "nc": 60, "spend": 1800 }
      },
      {
        "memberId": "total",
        "periodId": "prior",
        "sums": { "orders": 100, "nc": 50, "spend": 1700 }
      },
      {
        "memberId": "total",
        "periodId": "w1",
        "sums": { "orders": 60, "nc": 30, "spend": 900 },
        "ref": { "orders": 50 }
      },
      { "memberId": "paid", "periodId": "range", "sums": { "orders": 80, "nc": 45, "spend": 1800 } },
      { "memberId": "paid", "periodId": "prior", "sums": { "orders": 70, "nc": 38, "spend": 1700 } },
      {
        "memberId": "paid",
        "periodId": "w1",
        "sums": { "orders": 40, "nc": 22, "spend": 900 },
        "ref": { "orders": 35 }
      },
      { "memberId": "organic", "periodId": "range", "sums": { "orders": 40, "nc": 15 } },
      { "memberId": "organic", "periodId": "prior", "sums": { "orders": 30, "nc": 12 } },
      {
        "memberId": "organic",
        "periodId": "w1",
        "sums": { "orders": 20, "nc": 8 },
        "ref": { "orders": 15 }
      }
    ]
  },
  "options": { "variant": "by-measure", "depth": 2, "title": "Channel performance" }
}

Data

PathTypeRequiredMeaning
dimensionobjectyesOne hierarchical dimension.
dimension.labelstringyesDimension name, such as Channel. It heads the label column and the member section in by-member.
dimension.totalobjectyesSource total member.
dimension.total.idstringyesTotal member id in facts.
dimension.total.labelstringyesTotal row label.
dimension.total.headingstringby-measure: section heading over the measures before the first group. Absent, the total label.
dimension.total.fieldsarrayFields that apply even when the drawn windows hold only null.
dimension.membersarrayyesOne hierarchy of dimension members.
dimension.members[].idstringyesStable id or display label.
dimension.members[].labelstringyesStable id or display label.
dimension.members[].parentIdstringParent member id; absent for a top-level member.
dimension.members[].fieldsarrayFields that apply even when the drawn windows hold only null.
dimension.headlinearrayyesFolded by-member row figure: the first measure id here that applies to the member.
dimension.sumsbooleanTrue derives parent and total sums from children (default false: supplied sums). True records differences from supplied sums; with false, members need not add up.
measuresarrayyesKPI rows (a measure with parentId or splitOf is a split).
measures[].idstringyesStable id or display label.
measures[].labelstringyesStable id or display label.
measures[].valueobject | numberRequired, except on a subtotal (a measure that other measures name in partOf): absent, boardplot adds up its parts with their signs.
measures[].value.field (measures[].value branch 1)stringyesField name in facts[].sums.
measures[].value.measure (measures[].value branch 2)stringyesAnother measure's value, by measure id. A percent measure enters as a fraction (42.5% reads 0.425).
measures[].value.total (measures[].value branch 3)object | numberyesExpression over additive sums, other measures and constants. A Total operand evaluates its whole expression against dimension.total.id in the same current, prior, displayed-period ref or plan window. Nested Total keeps this scope.
measures[].value.op (measures[].value branch 5)stringyesArithmetic (x/0 prints n.m., 0/0 prints n/a). One of 'add', 'sub', 'mul', 'div'.
measures[].value.a (measures[].value branch 5)object | numberyesExpression over additive sums, other measures and constants. A Total operand evaluates its whole expression against dimension.total.id in the same current, prior, displayed-period ref or plan window. Nested Total keeps this scope.
measures[].value.b (measures[].value branch 5)object | numberyesExpression over additive sums, other measures and constants. A Total operand evaluates its whole expression against dimension.total.id in the same current, prior, displayed-period ref or plan window. Nested Total keeps this scope.
measures[].value.factor (measures[].value branch 5)numberMultiplier of the result: 100 for a percent level, 1000 for CPM.
measures[].scalestringPrecision rule from the largest absolute Range or period value; changes do not count. Money and count take it over every member row of the measure, so the measure prints in one magnitude: a member at 210k under a 1.2M total prints 0.21M, not 210.0k. Per unit and percent take it per row. Money: k, M or B with one decimal at 1000 or more, else whole units; every member row prints at the precision of the measure: a nonzero figure below it prints the bound (<0.01M), an exact zero prints 0, and a count never gains decimals. Per unit: fractional values keep authored precision. Without a format, start whole at 10 or more, else one decimal, then raise precision for rounding error above 1%, up to 20 decimals. Integer-only rows keep those defaults. Money and per unit drop format affixes; put the currency in unit. Count and percent keep the format; defaults 1,234 and 1.2%. Scaled money and automatic count rows add decimals for rounding error above 1% of the largest value of the measure in that column, up to 20, so a period column can print more decimals than the Range column; held whole thousands stay whole. Nonzero values never print as zero. Absent keeps the format. One of 'money', 'perUnit', 'count', 'percent'.
measures[].bandsarrayRange and period value bands in original units; percent levels use percentage points. Select the first value <= to, or the last band above all bounds. Missing tone means neutral. Bands replace level change colors; judge still colors comparisons. Partial windows and failed sample floors stay neutral.
measures[].bands[].tonestringSemantic band tone. One of 'good', 'warn', 'bad', 'neutral'.
measures[].bands[].tonumberyesUpper endpoint of this band in the value units.
measures[].bands[].labelstringVisible name of this band.
measures[].formatstringFormat example, such as 1.2% or 1,234; see scale.
measures[].unitstringUnit after the KPI label, such as EUR. A % or pp unit beside a percent format is left out.
measures[].parentIdstringSplit of this root measure: drawn under it only with splits on.
measures[].splitOfstringDual-role measure (a root with splits off, a split of this root with splits on). Cannot combine with parentId.
measures[].changestringChange shown: relative percent (default); pp, the difference of percent levels; absolute, current minus reference in the measure format with a sign (statement lines: the changes then add up down the statement). One of 'relative', 'pp', 'absolute'.
measures[].judgeobjectJudge the change against thresholds (unjudged money and count rows outside a statement draw bars).
measures[].judge.family (measures[].judge branch 1)stringyesThreshold family (cost is lower-is-better). One of 'volume', 'cost', 'rate'.
measures[].judge.base (measures[].judge branch 1)string | arrayyesOne field or a nonempty list of unique fields. All listed fields must meet their own minimumSample floor in every required member and Total window.
measures[].judge.family (measures[].judge branch 2)stringyesEffect on the statement result, in thresholds.effect units. One of 'effect'.
measures[].judge.base (measures[].judge branch 2)string | arrayOne field or a nonempty list of unique fields. All listed fields must meet their own minimumSample floor in every required member and Total window.
measures[].partOfstringStatement: the subtotal line this measure adds up into (a measure id). The subtotal value is the signed sum of its parts unless it has its own value.
measures[].signnumberStatement: the line subtracts (a cost authored as a positive amount). options.signs decides how it prints. One of -1.
measures[].resulttrueStatement: a result line. Its value names its lines, e.g. { op: 'sub', a: { measure: 'income' }, b: { measure: 'costs' } }. No sign, no partOf. One of true.
measures[].driversobject | numberStatement: how this line follows from driver measures, as a formula over { measure } and numbers, e.g. (AOV - returns) x margin. The named measures are drivers: printed under the same subtotal (or their own partOf), never added, judged by their effect.
measures[].drivers.measure (measures[].drivers branch 1)stringyesDriver measure id; its value may use Total operands.
measures[].drivers.op (measures[].drivers branch 3)stringyesArithmetic over driver measure values. One of 'add', 'sub', 'mul', 'div'.
measures[].drivers.a (measures[].drivers branch 3)object | numberyesDriver formula over measure references and constants only.
measures[].drivers.b (measures[].drivers branch 3)object | numberyesDriver formula over measure references and constants only.
measures[].drivers.factor (measures[].drivers branch 3)numberMultiplier of the result.
measures[].groupstringGroup label. by-measure heads each group with a section row; by-member nests the group under a label row in every member block.
measures[].dividertrueThe measure opens a family of KPIs: its rows take the rule above them. One of true.
measures[].inTotalBlockbooleanfalse leaves the measure out of the total block in by-member; by-measure keeps its total row. Default true.
groupHeadingsobjectby-measure section heading per measure group label. Absent, the group label heads its section.
effectLabelstringTag of a driver's effect in the cell hover text, such as Margin effect. Absent: no effect line. The line is hidden in the cell (inlineVisibility effect false) and shows in the hover.
changeLabelstringTag of the change line under each period value, such as WoW; it also opens the hover text of the cell.
periodsarrayyesOne range, one prior, zero or one plan, then at least one displayed period in order. The host owns dates and reference windows.
periods[].idstringyesStable id or display label.
periods[].labelstringyesColumn head (prior or plan: head of the comparison column, such as vs prior or vs plan).
periods[].subLabelstringSecond head line, such as W38 or dates.
periods[].partialbooleanCut or running window (muted, never judged). Its ref covers the same days one period earlier.
periods[].kindstringBlock role: range is the selection, prior the window of equal length before it. plan adds the Range vs-plan column (pl), without prorating. Absent for a displayed period. One of 'range', 'prior', 'plan'.
factsarrayyesAdditive sums per member and period, one entry each.
facts[].memberIdstringyesStable id or display label.
facts[].periodIdstringyesStable id or display label.
facts[].sumsobjectyesSums by field: an absent field drops its measures, null is missing, 0 is data. A field absent or null in every fact of a member does not apply to it, null in some facts is missing, and a host that means zero sends 0. With dimension.sums true, a member owes a field it reports in any period in every period, and a gap makes the parent sum missing.
facts[].refobjectSums of the period before (partial: the same days one period earlier). Only displayed periods take ref; Range compares with prior and optional plan.

Options

PathTypeValuesDefaultMeaning
mountCollapsedbooleanDefault true. false removes closed descendants from the React DOM and defers offscreen leaf paint.
paintOffscreenRowsbooleanReact only. true paints every mounted row at once, so a capture of a long table has no blank rows, and a long table paints slower. Default false. Closed rows follow mountCollapsed.
signsstring'signed', 'operators', 'plain'How sign -1 rows print. signed (default) negates them; operators draws + − × =; plain draws neither.
driverTonesstring'grouped', 'always', 'never'Driver tones. 'grouped' (default): drivers with a parentId whose parent is not a section heading do, as statement lines do. 'always': every driver. 'never': driver ink only, as before 0.28. Neutral figures and labels keep the driver ink.
judgmentsstring'all', 'exceptions'Which tones show. exceptions: strong good and bad only.
figuresbooleanPrint the cell figures; default true. false draws the heat grounds alone in 22 px cells, over any width authored for the figures, on 14 px rows or the line box of the text a row still prints where that is taller, so a sixty-column triangle fits one screen. The heads keep their labels and the numbers stay in the markup for a reader who cannot see the grounds. Refused on a table without a heat lane in encodings.
columnHeadsfalsefalsefalse: no visible head row and no group heads, with their height and rule. Assistive technology still reads the head in React, and sortable warns there.
inlineVisibilityobjectVisibility by inlineGroup. An absent group is visible, so a Changes control hides every MoM line of a table with one entry.
magnitudestring'auto', 'thousand', 'million'Money scale for all rows and columns. 'thousand' prints whole thousands, 'million' keeps the example's decimals, and no column rolls up on its own. The scale letter leaves the cells and hoists to the frame, the column header or, where the format sits on the row, the row label. 'auto' (the default) lets each column and money row pick from its own largest value.
nullsstring'blank', 'dash'What a MISSING cell prints. 'dash' (the default) keeps the em dash; 'blank' leaves it empty, which is what a cohort staircase needs — a cohort acquired in May has not been observed at M8, and a triangle of dashes is noise. The explicit states na, nm and suppressed keep their glyphs.
foldOnstring'row', 'toggle'React only. What folds a parent row. 'row': a click on the row folds it, and selects it too where the host made it selectable. 'toggle': only the fold mark folds; a row click only selects. Default: 'toggle' for a selectable row, else 'row'. Enter and Space follow the click.
groupGroundstring'expanded', 'always', 'none'Group row ground. 'expanded' (default): only an open group's header row. 'always': folded or open, as before 0.28. 'none': no group ground. The Total keeps its ground. Absent: theme table.groupGround.
anchorWashbooleanWash expanded level-0 anchors; no control.
stickyLabelsboolean | integer | objectPin header and columns. React only; static output shows the whole table. true pins one column, a number pins that many (2 for a cohort grid), and the last carries a hairline shadow. The object form sets head, columns, top and sections. Page mode is refused with React fillHeight. Off in print.
stickyLabels.headstring | false'table', 'page', falseHead pin mode. 'table' (default): in the table's own scroll box, which the host sizes. 'page': to the page scroll at top px; the body has no vertical scroll box, and no overflow ancestor may sit above the table. false: no pinned head.
stickyLabels.columnsintegerColumns. Default 1.
stickyLabels.topnumberOffset in px. Clears a host toolbar. Default 0; above 0 needs head: 'page'.
stickyLabels.sectionsbooleanSection label. Default false. true keeps the active section label under the head until the next section starts.
frameFillstring'values', 'none''values'Under rowExtent 'frame'. 'values' (default): automatic value tracks grow in whole pixels, up to maxGrowth (default 2.5). An unauthored label track takes the rest. 'none': columns keep their widths; an empty track carries the row ground and rules to the edge.
heightFillstring'rows', 'none''rows'Spare canvas height. 'rows' (default) spreads it over leaf rows as air, up to 16 px a side. 'none' leaves it empty.
rowLabelLinesinteger2Lines a row label may take before a cut (default 2). A label breaks at a space or after _ - / or a dot, so a long campaign name wraps instead of ending in '…'. 1 keeps every label on one line; a higher count lets a row grow to its lines. A cut label keeps its full name in its title.
lastTrackFlexbooleanLast unauthored track takes the spare frame width when rowExtent is tracks. Default false.
rowExtentstring'tracks', 'frame''frame'Where rows end. 'frame' (default) fills the width inside the frame margins. An explicit 'frame' also carries row grounds and rules through authored side margins. frameFill controls track growth. 'tracks' stops rows at the last column. Column bands stop at their columns. Tables use horizontal rules and explicit column separators; there is no single vertical end rule.
sortIndicatorstring'all', 'sorted'Sortable headers with a chevron. 'all' (the default) draws one on every sortable header; 'sorted' draws it on the sorted one alone and keeps the others' reserve, so no track moves.
levelOffsetintegerShift body rows down the ladder. Default 0. A board whose top rows are groups rather than KPI lines reads one rung too heavy: 1 steps them down in size, weight, air, ground, indent and label ink, -1 steps them up. The rungs stay floored at the top and at the deepest step.
cellPadXnumberHorizontal cell padding in px. Default 12; only when it cannot fit, use 5 for 20–24 columns or 3 for 25 or more.
maxGrowthnumber | falsefalse (or another value of its type)2.5Value-track growth cap; default 2.5, false removes the cap. Applies to SVG and React frame fill; the label track takes the remaining width. Also caps React container fit growth.
labelIndentobjectTree indent from row edge. Absent: cell air without marks; cell air plus 24 with outlineMarks: true or interactive fold buttons. Then 16 per rung.
labelIndent.basenumberLevel-0 start from row edge, padding included.
labelIndent.stepnumberpx per rung; default 16.
outlineMarksbooleanfalseFold marks beside parent rows. Drawn in static SVG/PNG and read-only grids. Default false: no marks or gutter. true draws the marks and reserves their gutter. Interactive grids keep their fold buttons either way.
encodingsobjectPer-column opt-in visual encodings. A key is a column id: range, pp (the vs prior column), pl (the vs plan column, with a plan) or the id of a displayed period. Any other key draws nothing and warns dimswitch-encoding-column.
encodings.*.type (encodings.* branch 5)string'arrow'Select the arrow lane.
encodings.*.scale (encodings.* branch 5)string'absolute', 'relative''absolute' cuts the change itself at 10 and 2 (points on a percent column); 'relative' cuts its share of the column's largest change at 10% and 2%. Default 'absolute' on a percent column, 'relative' elsewhere.
encodings.*.type (encodings.* branch 6)string'heat'Select the heat lane.
encodings.*.cap (encodings.* branch 6)objectWhere the lane saturates; without it the largest magnitude in the column does, on both sides of zero. Lanes with different caps add the note that shading compares values within each column.
encodings.*.cap.pct (encodings.* branch 6)numberPercent-column tint cap in points. Example: 20 for a ±20% YoY lane.
encodings.*.cap.abs (encodings.* branch 6)numberOther numeric tint cap in source units.
encodings.*.alpha (encodings.* branch 6)numberTint weight at the cap; default 0.18, and 0.26 on scale 'status', where every painted cell takes it. Text stays readable up to 0.18 on every shipped theme and up to 0.35 on a status ground; above that the figures take the contrast ink.
encodings.*.excludeTotals (encodings.* branch 6)booleanLeave total rows untinted; default true. Heat reads a variance, and a total has none worth coloring.
encodings.*.steps (encodings.* branch 6)integerBand count. 5 gives the cohort ladder: 6 / 14 / 26 / 42 % of the ink over the background, then the full ink with inverse text, from the theme token surface.heatSteps. A stepped lane measures the data rows only, so a closing row does not set the scale.
encodings.*.scale (encodings.* branch 6)string'column', 'absolute', 'diverging', 'status'Where a band comes from. 'column' (default) normalizes over this column's own min and max; with two or more such columns the table adds the note that shading compares values within each column. 'absolute' cuts at bins, so every column of a grid reads on one scale. 'diverging' measures the distance from the column average and paints good above and bad below; under polarity 'lowerIsBetter' the sides swap. 'status' is a traffic light against the same center: a value within tolerance of it paints warn, farther above good and farther below bad, the other way round on a column with polarity lowerIsBetter; it reads no steps, bins, span or cap.
encodings.*.bins (encodings.* branch 6)arrayAscending band edges. On scale 'absolute' a value takes the band of the last edge it reaches (e.g. [30, 40, 50, 60] gives five bands); on 'diverging' they are the |distance| edges, default [1, 4]. Given without steps, they set the band count themselves.
encodings.*.span (encodings.* branch 6)numberSpread that fills a column ramp. Measured in column units; a smaller spread takes bands from the lightest up, so a spread of 1 point is not painted like one of 30. Omitted, every column's own min and max fill the ramp.
encodings.*.center (encodings.* branch 6)string'total'Center: column total. On scales 'diverging' and 'status' a reader can check every band against that printed figure. Omitted, or in a column without a total row value, the center is the average of the column's data rows.
encodings.*.tolerance (encodings.* branch 6)objectWarn band of scale 'status'. A value at most this far from the center paints warn, the boundary included; default { pct: 5 }. Give exactly one of pct and abs.
encodings.*.tolerance.pct (encodings.* branch 6)numberPercent of the center. 5 reads 62 to 68 as warn around 65.
encodings.*.tolerance.abs (encodings.* branch 6)numberColumn units. 2 reads 63 to 67 as warn around 65.
encodings.*.columns (encodings.* branch 6)arrayFurther columns this rule paints. A sixty-column cohort grid names its lane once instead of sixty times, and a column that carries its own entry keeps it. Leave a column out to keep it unshaded.
columnVisibilityobjectTrue shows a column and false leaves it out: the ids are data.columnToggles ids on table and column ids elsewhere. Ids: label, range, pp, pl, each displayed period id. The label column stays, so hiding every value column draws labels only and warns. The data still needs its range and prior periods, and order and show still read Range.
columnOverridesobjectSettings per generated column. Ids: label, range, pp, pl, each displayed period id. width beats widths. The automatic card form sizes tracks by content and ignores width, except a smaller label width.
columnOverrides.*.widthnumberTrack width in px. It beats the width the type would pick.
columnOverrides.*.alignstring'left', 'right', 'center'Alignment of the column: its cell text and, unless headAlign is set, its head. Bars keep starting at the panel origin.
columnOverrides.*.headAlignstring'left', 'right', 'center'Head alignment; defaults to align.
columnOverrides.*.labelstringHead text.
columnOrderarrayOrder of whole blocks; blocks left out follow in default order. Ids: block, periods. block is Range and its comparisons. The label stays first, and only the label and leading block columns pin.
barsbooleanfalse turns the automatic size bars off. Scale, precision, data and judgment stay. Default true. A table that draws no bars warns option-ignored.
rowVisibilityobjectFalse leaves a generated row out. Ids: dimension.total.id, group:<measures[].group as authored>, and group: for the ungrouped section. A key equal to dimension.total.id means the Total. by-member: the whole Total block goes. by-measure: each Total line keeps its label and folds with blank cells, because it carries the KPI name and owns its members, and Total splits go. Facts stay for ratios and judgment. A hidden Total keeps the magnitude and decimals that members print with it, but where widths make a track narrow, format fitting follows the table as drawn, so a member can print 17.5% where the chart with the Total prints 18%. A group id removes its heads. These ids differ from expansion ids: expansion names one row of one variant, and rowVisibility names a block.
totalPositionstring'top', 'bottom'by-member: where the Total block sits, top (default) or bottom. In by-measure each Total row owns its members, so the key warns option-ignored. It also warns where rowVisibility hides the by-member Total block.
densitystring'compact', 'regular', 'relaxed'Cell spacing: 'compact', 'regular' or 'relaxed'. The cohort densities do not apply: every cell holds a value and a change line, and cohort rows are fixed one-liners.
variantstring'by-measure', 'by-member''by-measure'by-measure: KPI rows over members. by-member: members over KPIs, with the Total block at totalPosition. A fixed height may fold it.
depthinteger1Open rungs: 1 roots folded, 2 one member level open, 3 two levels; the same in both variants. Maximum member levels plus one. Splits add no rung.
splitsbooleanfalseShow split measures under their root measure.
expansionobjectRow-id exceptions over depth (id: JSON.stringify([variant, memberId, measureId])).
expansion.expandedarrayRow ids to open.
expansion.collapsedarrayRow ids to fold.
orderstring | object'sheet' (or another value of its type)Sibling order: sheet, or {by: measure id} on Range values, descending. Ties by id, missing values last.
order.bystringStable id or display label.
order.descbooleanDescending order; default true.
showstring'always', 'withData'withData hides a member only when every field of every measure that applies to it is zero or empty in Range; a member with any value there stays, because it still counts in the Total. Its child members hide with it.
thresholdsobjectChange thresholds, separate from value bands. Resolve each family: kind override, family setting, default (volume [2,10], cost [5,15], rate [3,10]). period controls displayed changes, prior controls pp, plan controls pl. Cost is lower-is-better; pp changes use relative levels. Effect needs an explicit pair for each used kind. Pairs satisfy 0 <= first <= second.
thresholds.volumearrayRelative percent change thresholds for volume; default [2,10].
thresholds.costarrayRelative percent change thresholds for cost; default [5,15], lower is better.
thresholds.ratearrayRelative percent change thresholds for rate; default [3,10].
thresholds.effectarrayEffect thresholds in the statement unit. An explicit pair must resolve for each used comparison kind.
thresholds.periodobjectFamily overrides for displayed-period changes. Unset families use the family setting or default.
thresholds.period.volumearrayRelative percent change thresholds for volume; default [2,10].
thresholds.period.costarrayRelative percent change thresholds for cost; default [5,15], lower is better.
thresholds.period.ratearrayRelative percent change thresholds for rate; default [3,10].
thresholds.period.effectarrayEffect thresholds in the statement unit. An explicit pair must resolve for each used comparison kind.
thresholds.priorobjectFamily overrides for pp, the Range vs-prior column.
thresholds.prior.volumearrayRelative percent change thresholds for volume; default [2,10].
thresholds.prior.costarrayRelative percent change thresholds for cost; default [5,15], lower is better.
thresholds.prior.ratearrayRelative percent change thresholds for rate; default [3,10].
thresholds.prior.effectarrayEffect thresholds in the statement unit. An explicit pair must resolve for each used comparison kind.
thresholds.planobjectFamily overrides for pl, the Range vs-plan column.
thresholds.plan.volumearrayRelative percent change thresholds for volume; default [2,10].
thresholds.plan.costarrayRelative percent change thresholds for cost; default [5,15], lower is better.
thresholds.plan.ratearrayRelative percent change thresholds for rate; default [3,10].
thresholds.plan.effectarrayEffect thresholds in the statement unit. An explicit pair must resolve for each used comparison kind.
widthsobjectFixed track widths of the value columns.
widths.labelnumberWidth of the whole label track in px, indent and affix included. It stays fixed when the frame has room. Absent, the label text adds up to 320 px, indent and affix on top; wider content lets labels use the room.
widths.rangenumberRange track in px; default 110.
widths.changenumberChange track in px; default 92.
widths.periodnumberTrack of each period in px; default 94.
minimumSampleobjectMinimum judge base per sum field in BOTH windows (below it: neutral). Default none.

Plus the shared options. This type does not accept format, detailFields, labels, labelPosition, valueAxis, story, hatchStrength, rounding, annotations, groupRule, groupAlign. This type ignores animate, debug, rowLabels, categoryAxis, categoryLabels, secondaryAxis, topN, bandFraction, legend, valueAxis.show, valueAxis.gridlines, focus, labelDensity with an option-ignored warning.

Annotations

This type takes no annotations.

What the table is for

Use dimswitch for a KPI report over one dimension and a run of periods: for example orders, revenue, spend and CAC by channel, week by week. The reader switches the same numbers between two variants: KPI rows with the channels under each KPI, or channel rows with the KPIs under each channel. The reader also opens the rows level by level, shows split measures, and shows or hides the change lines.

The host supplies additive sums: one set for each member and period. Boardplot computes ratios, differences, changes, judgment and display formats from these sums. The layout result keeps the calculation records in computedCells. Amount and change records contain a full expression in op and its source values in inputs. Source references name the member, period, sums or ref window, and field.

CLI and MCP manifests publish amount, change and partition records. The reading lists numeric derivations and marks whether each value is drawn. A hidden record has an empty displayed value. Exact raw values stay unchanged. Unavailable results retain their state as records without an arithmetic promise; the reading does not list them as numeric derivations. Effect and Shapley records still lack source operands and are not published as verifiable calculations.

Do not use dimswitch for these cases:

Read the sections below in order: Mental model, Host data, Measures, Statements, View options, Worked example, React usage and Common mistakes. The Data and Options tables above list every field.

Mental model

The data is a cube with three axes: the measures (one measure is one KPI), one hierarchical dimension (members with parentId, under one Total) and the periods. Each value cell is computed from the sums of one member in one window.

The columns are the same in every view. The label column comes first; its head is KPI in by-measure and dimension.label in by-member. The Range column shows the whole selection. The vs prior column shows the change of Range against the Prior window. Then comes one column for each displayed period. The label, Range and vs prior columns stay pinned while the periods scroll.

variant chooses the row tree. by-measure (the default) puts the measures of the Total at the top and the members under each measure. This is the outline of the worked example at depth 3 with splits off:

KPI                                (head of the label column)
ALL CHANNELS                       section row: dimension.total.heading
Orders                             rung 0: a measure of the Total
  Paid search                      rung 1: a top-level member
    Brand search                   rung 2: a child member
    Generic search
  Paid social
  Email
New customers                      the same members under every measure
  ...
New-customer share
Net revenue                        divider: true draws a rule above it
AOV
PAID MEDIA, CHANNELS WITH SPEND    section row of the group "Paid media"
Marketing spend
  Paid search
    Brand search
    Generic search
  Paid social                      Email has no spend, so it has no row here
CAC
  ...

by-member starts with the Total block, then a section row with dimension.label, then one row for each top-level member. An open member row shows its member block: its measures one step in, then its child members. This is the same example in by-member at depth 3:

Channel                            (head of the label column: dimension.label)
Total                              the Total block: always open, no figures
  Orders
  New customers
  New-customer share
  Net revenue
  AOV
  Paid media                       group label row
    Marketing spend
    CAC
CHANNEL                            section row: dimension.label
Paid search                        rung 0; folded, it shows its headline figure
  Orders                           the member block
  ...
  Paid media
    Marketing spend
    CAC
  Brand search                     rung 1: a child member with its own block
    Orders
    ...
  Generic search
Paid social
Email                              no spend: no Paid media group
  Orders
  ...

depth opens the row tree level by level, like the outline buttons 1, 2 and 3 of a spreadsheet. Every row that can fold has an outline level, and depth d shows the rows of level d or less. Without a statement, the levels are the member levels, with the same meaning in both variants. Depth 1 shows the measures of the Total only; by-member also shows the top-level members as folded rows. Depth 2 also shows every measure of the top-level members. Depth 3 also shows every measure of their children. In general, depth d shows the measures of the Total and of d − 1 member levels; by-member also shows the next member level as folded rows. The maximum depth is the number of member levels plus one, so 3 for a dimension with two levels. A statement adds levels: see Depth with a statement. Section rows, group label rows, split rows and change lines take no level.

On a fixed height, such as a slide or a print canvas, a table that misses the height at its depth draws one fold shallower, down to depth 1. By-member then also folds the Total. The table keeps the deepest fold that fits and warns with dimswitch-depth-folded, whose fix sets options.depth and, where the Total folded, adds its row to expansion.collapsed. An open height grows to its rows and never folds. A folded table prints each figure with the text of the open table: its decimals come from every row, also the rows the fold hides. Where depth 1 still misses, the size refusal names the least height the folded table needs.

These are the row counts of the worked example. They include section rows and group label rows, not change lines.

variantsplitsdepth 1depth 2depth 3
by-measureoff92842
by-measureon103248
by-memberoff133652
by-memberon144058

splits is a separate switch, not a depth. A split is a measure with parentId: it shows only when splits are on, one step under its root measure, wherever the root measure has a row (under the Total and under every member). A dual-role measure has splitOf instead: with splits off it is a root measure of its own, and with splits on it moves under its root measure. In the worked example, New customers is dual-role and Existing customers is a split of Orders.

group collects measures. In by-measure each group starts a section row. groupHeadings sets the text of that row, and dimension.total.heading names the section over the measures before the first group. by-measure has section rows only when at least one measure has a group. In by-member each member block shows a group label row with the measures of the group under it. A member for which no measure of the group applies shows no group label row. divider: true draws a rule above the rows of a measure, to start a family of KPIs without a section row.

In by-member the Total block is open unless expansion.collapsed names its row. A folded Total shows its headline like a folded member row, and a table on a fixed height folds it after depth 1 (see the fixed height above). inTotalBlock: false leaves a measure out of the Total block, for example a platform KPI that has no meaning for the total; by-measure keeps the Total row of that measure. A folded member row shows its headline: the first measure in dimension.headline that applies to the member. The measure label and unit follow the member label, for example Paid search Marketing spend, USD. An open member row shows no figures.

Host data: what to supply and how to compute it

Boardplot does no date arithmetic. Do these steps in the host, in SQL or in code, and pass the result as data:

  1. Choose the windows. Range is the selection, for example 14 Sep to 7 Oct. Prior is the window of the same length directly before it, here 21 Aug to 13 Sep. The displayed periods are the calendar units inside the range, such as ISO weeks (Monday to Sunday) or months.
  2. Mark the partial periods. A period is partial when the range cuts it, or when it is still running (its last day is after the last day with data). Set partial: true. Boardplot mutes the column and never judges it.
  3. Find the reference window of each displayed period. For a full period, it is the unit before: W39 for W40. For a partial period, it is the same days of the unit before: W41 from Monday to Wednesday compares with Monday to Wednesday of W40. For a month cut after day 7, use days 1 to 7 of the month before; when the month before is shorter, stop at its last day. Range has no reference window of its own: it compares with Prior.
  4. Sum each additive field for each member and window. Put the sums of the window in sums and the sums of its reference window in ref. Supply one fact for the Total and for each member in each period, including Range and Prior. Range and Prior take no ref.
  5. Write periods in this order: the range block, the prior block, then the displayed periods. label is the first head line and subLabel the second, such as 14 Sep and W38. The prior label heads the vs prior column, so write vs prior there and put the dates of the Prior window in its subLabel.

Supply sums, never ratios. A field in sums is a total that you can add: orders, revenue, spend, new customers, sessions. Do not put a ratio, an average or a rate in sums. Boardplot computes CAC as the spend sum divided by the new-customer sum of the same window, which is the weighted ratio. An average of daily ratios gives a different, wrong number: a day with spend 100 and 1 new customer (CAC 100) and a day with spend 900 and 30 new customers (CAC 30) average to 65, but the true CAC is 1,000 / 31 = 32.3. Boardplot also needs the parts to compute the ratio again for each member and for the Total.

This query sketch gives one result row for each member and window. daily holds one row for each day and leaf channel. rollup maps each member to the leaves it covers; the total covers every leaf. windows holds Range, Prior and each displayed period, with ref_first and ref_last null for Range and Prior.

SELECT w.period_id, r.member_id,
  SUM(CASE WHEN d.day BETWEEN w.first_day AND w.last_day THEN d.orders END)        AS orders,
  SUM(CASE WHEN d.day BETWEEN w.first_day AND w.last_day THEN d.new_customers END) AS nc,
  SUM(CASE WHEN d.day BETWEEN w.first_day AND w.last_day THEN d.spend END)         AS spend,
  SUM(CASE WHEN d.day BETWEEN w.ref_first AND w.ref_last THEN d.orders END)        AS ref_orders,
  SUM(CASE WHEN d.day BETWEEN w.ref_first AND w.ref_last THEN d.new_customers END) AS ref_nc,
  SUM(CASE WHEN d.day BETWEEN w.ref_first AND w.ref_last THEN d.spend END)         AS ref_spend
FROM windows AS w
CROSS JOIN rollup AS r
JOIN daily AS d ON d.leaf_id = r.leaf_id
GROUP BY w.period_id, r.member_id;

Map each result row to one fact: { "memberId": member_id, "periodId": period_id, "sums": { "orders": orders, "nc": nc, "spend": spend }, "ref": { "orders": ref_orders, "nc": ref_nc, "spend": ref_spend } }. A SQL SUM over no rows gives NULL. Change that NULL to 0 for a field that applies to the member, and remove the key for a field that does not apply. The React usage example does this mapping.

A measure applies to a member when every local field that its value reads has a number in at least one fact of that member. Otherwise boardplot leaves the row of that measure out for that member. If the Total lacks a field, the measure is left out everywhere, with the warning dimswitch-measure-omitted and an entry in reading.omissions. With dimension.sums: true the Total has a field when at least one member has a number for it. The three states of a field mean different things:

To keep a row when the selected windows hold only null for a field, declare the field on the member: { "id": "email", "label": "Email", "fields": ["spend"] } (and dimension.total.fields for the Total). The row then stays and prints the missing glyph. A statement line never leaves by applicability: see Statements. Decide applicability on the whole source data, not on the selected range, so rows do not appear and disappear when the reader changes the range. Source tables often fill spend with 0 for channels that never have spend. Remove that field or set it to null for those members; a 0 draws Marketing spend 0 and CAC 0.0 rows.

By default boardplot uses the sums that you supply for every member and for the Total. Members do not have to add up to their parent: a channel list can leave out small channels, and members can overlap. Set dimension.sums: true only for a true partition. Boardplot then derives the sums of each parent, and of the Total, from its children, so supply no fact for the Total or for a parent member; for both sums and ref, and records the difference to any supplied parent sum as a reconciliation record. A field that a child reports in no fact adds up over the other children. A child that reports a field in any period owes it in every period: a null value, a missing field or a missing fact makes the parent value null, and the Total prints the missing glyph. A missing fact or field also gives the warning dimswitch-fact-missing, which names the member and the periods. Send null for an unknown value and 0 for none.

Measures: values, formats, changes and judgment

value is an expression over the field names in sums: { "field": "orders" }, or { "op": "add" | "sub" | "mul" | "div", "a": ..., "b": ..., "factor": 100 }. An operand can also be another measure, { "measure": "income" }, or a number. A percent measure enters as a fraction: a margin of 42.5% reads 0.425. Expressions nest, and factor multiplies the result of its own operation. Examples:

{ "total": expression } evaluates its whole expression against dimension.total.id in the same window. This includes expanded measure references, prior, displayed-period ref, and plan. Nested Total operands keep that scope. Total fields do not become required member fields. A missing Total input keeps the applicable member row and prints missing. show: "withData" still checks the member fields. Calculation records name the Total member and source window. Use this operand in measure values, including driver values; drivers formulas still accept only measure references and numbers.

Boardplot evaluates the expression on the sums of each member and window, and again on the reference sums for the change. A missing operand gives a missing cell (—). A division by zero prints n.m.; 0 divided by 0 prints n/a.

scale sets the precision of a row from its own values. Boardplot takes the largest absolute value of the row in Range and in the displayed periods; the vs prior column and the change lines do not count.

Scaled money and automatic count rows add decimals when rounding error exceeds 1%, up to 20 decimals. The row keeps one precision and its existing magnitude. An explicit whole-thousand scale stays whole.

money drops the prefix, suffix and decimals of format. perUnit drops the prefix and suffix, but keeps authored precision for fractional values. Put the currency in unit. The unit prints after the KPI label, such as Net revenue USD, and not in the cells. Member rows and split rows repeat no unit. A % or pp unit next to a percent format is left out, because the cells already show it. A nonzero value never prints as zero: the row takes more decimals (0.004).

Each period value has a change line under it, and Range has the vs prior column. change: "relative" (the default) prints the percent change against the reference: whole percent from 5% and at 0% (+7%), and one decimal below 5% (+4.2%). With relative, a change of 1,000% or more, or a reference of 0 or less, prints n.m. A missing reference prints n/a. 0 against 0 prints nothing. A displayed period whose facts carry no ref has no change line at all, and a period where only some facts lack ref prints n/a for those members. change: "pp" prints the difference of the two percent levels with one decimal (+0.9pp). Use pp for shares and rates. change: "absolute" prints the current value minus the reference value, in the measure format with a sign (+0.4). Use it on statement lines, where the changes add up down the statement.

judge colors a measure. family sets the direction and the default thresholds: volume (higher is better, [2, 10]), cost (lower is better, [5, 15]) and rate (higher is better, [3, 10]). The thresholds are relative percent changes. A favorable change of at least the first threshold is good, and of at least the second threshold strong good. An adverse change of at least the first threshold is warn, and of at least the second threshold bad. A smaller change is neutral. A pp measure is also judged on the relative change of its level: a share that goes from 40% to 41.2% is +3% relative, which is good for a rate, while the cell prints +1.2pp. There is no lower-is-better rate family in 0.24.0: for a rate where lower is better (a return rate or a bounce rate), use cost, which shares thresholds.cost with CAC. A statement line can use the family effect instead: see Statements.

measures[].bands colors Range and displayed-period values. Each band has to, optional tone and optional label. Use a nonempty list with finite, strictly ascending bounds. The first band with value <= to wins. Below all bounds uses the first; above all bounds uses the last. Values are unrounded and in their original units; percent levels use percentage points. An omitted tone means neutral. Partial or missing values stay neutral. Bands use the current sample floors when judge.base exists; changes still use judge and both windows. Without bands, level colors stay unchanged.

A ratio of the Total divides the Total sums. Total CAC divides all spend by all new customers, including the new customers of members without spend. For a paid-only CAC, supply a field such as nc_paid that is absent or null for members without spend, and use it as the denominator.

judge.base accepts a field name or a nonempty list of unique field names, such as ["orders", "sessions"]. All listed fields must meet their own minimumSample floor in every required window. Missing or null fields fail, even with the default floor of zero. Equality passes. Changes require current and reference samples; value bands require only the current sample. Total-dependent measures also check the same declared fields in their Total windows. No extra base field is inferred. A failed floor changes only the tone; values and changes stay visible. Without bands, Range stays neutral and the vs prior column carries its judgment. A measure without judge prints its comparison changes muted.

A money or count measure without judge is a size, not a performance. Its period cells draw a gray bar, scaled to the largest full period of the row. Its Range cells draw a bar scaled to the largest member of the same measure; the Total row has no Range bar.

The order of measures is the row order; splits follow their root measure. A split cannot have splits of its own, and a measure cannot have both parentId and splitOf. dimension.headline lists the measures for folded member rows in by-member: put the measure that best sums up a paid channel first (spend), then a fallback for the members where it does not apply (revenue).

Statements: subtotals, results and drivers

A statement is a group of measures that add up to results, such as a contribution-margin (CM) statement per order or a P&L in money. It sits in the same table as the KPIs, under its own section. Give its measures one group: that group is the statement. A group is a statement when any of its measures has partOf, sign, result or drivers, or is named by the partOf or drivers of another measure. A part takes the group of its subtotal, so give group to the top-level lines only.

Each statement line has one of four roles:

Supply costs as positive sums and set sign: -1 on the line that subtracts. Set it on the subtotal Costs, not on each part: the contribution sign of a line is the product of the signs up its partOf chain, so Shipping under Costs subtracts. Boardplot computes values, relative changes and n.m. rules on the supplied values, before any sign. The table option signs decides how a sign prints:

In operators mode a cost that rises prints a positive change, because values print as supplied; the color still shows the effect. Each figure rounds on its own, so a printed subtotal can differ by one in the last digit from the sum of its printed parts; boardplot adds the exact values.

Write a per-order line as a ratio of sums: { "op": "div", "a": { "field": "ship" }, "b": { "field": "orders" } }. Use the same denominator for every line of a per-unit statement, so the parts add up to their subtotal in every window. Boardplot divides the sums of each window, so Range is the weighted value of the whole selection, never an average of the weeks. Give statement lines a fixed format such as 1.2 when small changes need a fixed decimal place. Use scale: "perUnit" to keep that precision for fractional values and place the currency in unit. Omit scale to keep the format on every value. Boardplot assumes no currency. Put the currency in unit, in the group heading or in the format (€1.2, CHF 1.2).

Set change: "absolute" on statement lines. In signed mode, the absolute changes of the parts then add up to the change of their subtotal, and the changes of the lines add up to the change of each result. A percent driver, such as a gross margin, uses pp. relative stays possible, but relative changes do not add up.

A line with drivers names them in a formula over { "measure": id } and numbers. Gross profit per order = (price before discounts − returns per order) × gross margin is "drivers": { "op": "mul", "a": { "op": "sub", "a": { "measure": "aovbd" }, "b": { "measure": "ret" } }, "b": { "measure": "gm" } }. A percent measure enters the formula as a fraction. Boardplot checks in every window that the formula gives the value of the line, and warns dimswitch-driver-footing when it does not; the warning names a percent driver that has a factor: 100 value but no scale: "percent". The drivers print in the block of the line they explain, after its parts: here under Income, after Gross profit and Delivery charges. Set partOf on a driver to place it elsewhere. A line can have at most six drivers. Define a percent driver on the base the formula uses: a gross margin of { "op": "div", "a": { "field": "gp" }, "b": { "op": "sub", "a": { "field": "revbd" }, "b": { "field": "returns" } }, "factor": 100 } with scale: "percent" makes (AOV − returns) × margin give gross profit exactly.

judge: { "family": "effect" } colors a statement line by its effect on the statement result, in the statement unit. The effect of a line is its change times its contribution sign: when shipping costs rise by 0.4 per order, the effect is −0.4. The effect of a driver is its share of the change of the line it explains, times the contribution sign of that line. Boardplot splits the change of the line with the Shapley method: the effect of each driver is its marginal effect, averaged over every order in which the drivers can move. The shares add up exactly to the change of the line. For (A − R) × m this is the midpoint rule: ΔA × average m, −ΔR × average m and Δm × average (A − R). The split is arithmetic; it does not prove a cause.

Set the effect thresholds in the statement unit: options.thresholds.effect: [0.3, 1] means 0.3 and 1 currency per order. An effect of 0.3 or more is good, of 1 or more strong good; −0.3 or less is warn, −1 or less bad. An explicit effect pair must resolve for each used comparison kind: use the family pair or thresholds.period.effect, thresholds.prior.effect and thresholds.plan.effect. Boardplot refuses effect lines with different scales or formats, because one pair of thresholds cannot judge two units. Drivers are exempt: their effect is in the unit of the line they explain. Use thresholds for the currency of the data; do not reuse EUR thresholds for CHF or for total money. judge.base is optional for effect and keeps its minimumSample meaning. A partial period, a missing value and an effect of 0 stay neutral. data.effectLabel, such as "Margin effect", adds the effect of each driver cell to its hover text; that line stays hidden in the cell (inlineVisibility.effect is false unless you set it).

A statement line never leaves the table because of applicability. A missing field prints the missing glyph (—), and a subtotal or result that reads it is missing too, never a smaller number. With dimension.sums: true, a member fact that lacks a statement field makes the parent sum missing for that period; a member with no fact in a period adds nothing. Statement lines draw no size bars.

Depth with a statement counts the statement levels too. In by-measure the statement opens first, then the members: depth 1 shows the top-level lines, depth 2 also the parts of each subtotal, and depth 3 also the members under every line. A KPI outside the statement opens its members at the same depth as the statement lines, so one depth means one thing across the table. A line with parts or drivers under it has no member rows in by-measure; read a subtotal per member in by-member. In by-member the members open first, then the statement: with one member level, depth 2 opens the member blocks and depth 3 the parts of each subtotal in every block. A Total-only statement (no members) has two depths: 1 folded, 2 open. A result has no rows under it, so it shows at every depth.

This is the outline of the example below at depth 2, with the operators of signs: "operators":

ORDERS
Orders
CONTRIBUTION MARGIN · USD PER ORDER · CHANGES IN USD
Income                     subtotal
    Gross profit           part (explained by the three drivers)
  + Delivery charges       part
    Price before discounts driver
  − Returns and refunds    driver
  × Gross margin           driver (percent, pp change)
− Costs                    subtotal with sign -1
    Payment fees           part
  + Delivery
  + Handling
= Margin after order costs result
− Sales costs              subtotal with sign -1
    Advertising
  + Promotions
= Final margin             result, closing double rule
{
  "type": "dimswitch",
  "data": {
    "dimension": {
      "label": "Shop",
      "total": { "id": "total", "label": "Total", "heading": "Orders" },
      "members": [],
      "headline": ["orders"]
    },
    "changeLabel": "WoW",
    "effectLabel": "Margin effect",
    "groupHeadings": { "Contribution margin": "Contribution margin · USD per order · changes in USD" },
    "measures": [
      {
        "id": "orders",
        "label": "Orders",
        "value": { "field": "orders" },
        "scale": "count",
        "judge": { "family": "volume", "base": "orders" }
      },
      {
        "id": "income",
        "label": "Income",
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "group": "Contribution margin"
      },
      {
        "id": "gp",
        "label": "Gross profit",
        "value": { "op": "div", "a": { "field": "gp" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "income",
        "drivers": {
          "op": "mul",
          "a": { "op": "sub", "a": { "measure": "aovbd" }, "b": { "measure": "ret" } },
          "b": { "measure": "gm" }
        }
      },
      {
        "id": "shipi",
        "label": "Delivery charges",
        "value": { "op": "div", "a": { "field": "shipi" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "income"
      },
      {
        "id": "aovbd",
        "label": "Price before discounts",
        "value": { "op": "div", "a": { "field": "revbd" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" }
      },
      {
        "id": "ret",
        "label": "Returns and refunds",
        "value": { "op": "div", "a": { "field": "returns" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" }
      },
      {
        "id": "gm",
        "label": "Gross margin",
        "value": {
          "op": "div",
          "a": { "field": "gp" },
          "b": { "op": "sub", "a": { "field": "revbd" }, "b": { "field": "returns" } },
          "factor": 100
        },
        "scale": "percent",
        "change": "pp",
        "judge": { "family": "effect" }
      },
      {
        "id": "costs",
        "label": "Costs",
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "sign": -1,
        "group": "Contribution margin"
      },
      {
        "id": "pay",
        "label": "Payment fees",
        "value": { "op": "div", "a": { "field": "pay" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "costs"
      },
      {
        "id": "ship",
        "label": "Delivery",
        "value": { "op": "div", "a": { "field": "ship" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "costs"
      },
      {
        "id": "pick",
        "label": "Handling",
        "value": { "op": "div", "a": { "field": "pick" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "costs"
      },
      {
        "id": "cm2",
        "label": "Margin after order costs",
        "value": { "op": "sub", "a": { "measure": "income" }, "b": { "measure": "costs" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "group": "Contribution margin",
        "result": true
      },
      {
        "id": "mkt",
        "label": "Sales costs",
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "sign": -1,
        "group": "Contribution margin"
      },
      {
        "id": "spend",
        "label": "Advertising",
        "value": { "op": "div", "a": { "field": "spend" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "mkt"
      },
      {
        "id": "disc",
        "label": "Promotions",
        "value": { "op": "div", "a": { "field": "disc" }, "b": { "field": "orders" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "partOf": "mkt"
      },
      {
        "id": "cm3",
        "label": "Final margin",
        "value": { "op": "sub", "a": { "measure": "cm2" }, "b": { "measure": "mkt" } },
        "format": "1.2",
        "change": "absolute",
        "judge": { "family": "effect" },
        "group": "Contribution margin",
        "result": true
      }
    ],
    "periods": [
      { "id": "range", "label": "Range", "subLabel": "7 to 23 Sep", "kind": "range" },
      { "id": "prior", "label": "vs prior", "subLabel": "21 Aug to 6 Sep", "kind": "prior" },
      { "id": "w1", "label": "7 Sep", "subLabel": "W37" },
      { "id": "w2", "label": "14 Sep", "subLabel": "W38" },
      { "id": "w3", "label": "21 Sep", "subLabel": "to 23 Sep", "partial": true }
    ],
    "facts": [
      {
        "memberId": "total",
        "periodId": "range",
        "sums": {
          "orders": 2400,
          "revbd": 172800,
          "returns": 2160,
          "gp": 75060,
          "shipi": 6000,
          "pay": 4320,
          "ship": 25200,
          "pick": 6480,
          "spend": 72000,
          "disc": 8400
        }
      },
      {
        "memberId": "total",
        "periodId": "prior",
        "sums": {
          "orders": 2200,
          "revbd": 156200,
          "returns": 1760,
          "gp": 67430,
          "shipi": 5720,
          "pay": 3960,
          "ship": 23320,
          "pick": 5940,
          "spend": 70400,
          "disc": 7480
        }
      },
      {
        "memberId": "total",
        "periodId": "w1",
        "sums": {
          "orders": 800,
          "revbd": 56800,
          "returns": 640,
          "gp": 24710,
          "shipi": 2000,
          "pay": 1440,
          "ship": 8480,
          "pick": 2160,
          "spend": 25600,
          "disc": 2800
        },
        "ref": {
          "orders": 760,
          "revbd": 53960,
          "returns": 680,
          "gp": 23230,
          "shipi": 1900,
          "pay": 1370,
          "ship": 8130,
          "pick": 2050,
          "spend": 25080,
          "disc": 2660
        }
      },
      {
        "memberId": "total",
        "periodId": "w2",
        "sums": {
          "orders": 860,
          "revbd": 62780,
          "returns": 860,
          "gp": 27250,
          "shipi": 2150,
          "pay": 1550,
          "ship": 8940,
          "pick": 2320,
          "spend": 24940,
          "disc": 3010
        },
        "ref": {
          "orders": 800,
          "revbd": 56800,
          "returns": 640,
          "gp": 24710,
          "shipi": 2000,
          "pay": 1440,
          "ship": 8480,
          "pick": 2160,
          "spend": 25600,
          "disc": 2800
        }
      },
      {
        "memberId": "total",
        "periodId": "w3",
        "sums": {
          "orders": 380,
          "revbd": 27360,
          "returns": 300,
          "gp": 11910,
          "shipi": 950,
          "pay": 680,
          "ship": 3990,
          "pick": 1030,
          "spend": 11400,
          "disc": 1140
        },
        "ref": {
          "orders": 370,
          "revbd": 27010,
          "returns": 330,
          "gp": 11550,
          "shipi": 930,
          "pay": 670,
          "ship": 3850,
          "pick": 1000,
          "spend": 11100,
          "disc": 1220
        }
      }
    ]
  },
  "options": {
    "title": "Margin after order costs rises 0.6 to 18.8 per order as sales costs fall 1.9",
    "depth": 2,
    "signs": "signed",
    "thresholds": { "effect": [0.3, 1] },
    "widths": { "range": 120, "change": 120 }
  }
}

View options

variant (by-measure by default, or by-member), depth (1 by default) and splits (false by default) choose the view; see Mental model. In React they are props that the host controls.

expansion adds row-id exceptions on top of the depth defaults: expanded opens rows and collapsed folds rows. A row id is the JSON text of an array: ["by-measure","total","spend"] is the Total row of Marketing spend in by-measure, ["by-measure","search","cac"] is the Paid search row under CAC, and ["by-member","search"] is the Paid search member row in by-member. A change line has the id of its row plus :change. Build the ids with dimswitchRowId(variant, memberId, measureId) from boardplot (it returns JSON.stringify([variant, memberId, measureId])), and leave out measureId for a member row in by-member. An id of the other variant has no effect. An expanded row shows only when all its parents are open, and an id of a hidden row has no effect and gives no warning. In by-measure at depth 1, to show the Paid search row of Marketing spend, expand the Total row of Marketing spend as well: [dimswitchRowId("by-measure", "total", "spend"), dimswitchRowId("by-measure", "search", "spend")]. The worked example opens the Paid search rows of Marketing spend and CAC this way.

order sorts the members among their siblings. "sheet" (the default) keeps the order of dimension.members. { "by": "revenue" } sorts by the Range value of that measure, descending; "desc": false sorts ascending. Ties sort by member id, and missing values come last. show: "withData" hides a member only when every field of every measure that applies to it is zero or empty in Range; a member with any value there stays, because it still counts in the Total. Its child members hide with it. A member with no measure field that applies always shows.

An optional period with kind: "plan" adds one pl comparison column: label, Range, vs prior (pp), vs plan (pl), then displayed periods. Zero or one plan is allowed. At least one displayed period is required. pl is a reserved column id. The plan label and subLabel head pl; widths.change sets its width. The host must supply comparable actual and plan windows. Boardplot does not prorate plan or use prior as a fallback. Sample floors must pass in actual and plan. A partial Range or plan disables plan judgment. Plan uses the same change modes and effect calculations as prior.

thresholds.period, thresholds.prior and thresholds.plan override change thresholds for displayed changes, pp and pl. Resolve each family separately: kind override, family setting, then family default. Defaults remain volume [2,10], cost [5,15] and rate [3,10]. Each pair must be finite and satisfy 0 <= first <= second. Effect needs an explicit pair for each used kind. These thresholds judge changes, separate from value bands.

thresholds replaces the thresholds of a family, such as { "cost": [3, 12] }. minimumSample sets the smallest judge base for each sum field, such as { "orders": 30, "nc": 20 }; see Measures.

inlineVisibility: { "change": false } hides the change lines. They are visible when you do not set it. In React, the hover text of each period cell still shows the change, tagged with changeLabel, such as WoW +24%.

widths fixes the track widths in px: label is the cap of the whole label column, indent and affix included (a longer label is cut; absent, the label text adds up to 320 px to the column, with the indent and the affix on top, and a column made wider by other content lets labels use the room), range the Range column (110), change each vs prior or vs plan column (92) and period each period column (94). Widen range and change when their subLabel holds dates. Render the table at the width the page shows it: at a narrow width a long unit can cut the KPI label.

dimswitch takes the table options except topN. It always draws the steering table. It sets these defaults, and an option that you set wins: stickyLabels: 3 (label, Range and vs prior pinned), or 4 when plan is present, rowExtent: "frame", mountCollapsed: false (closed rows stay out of the DOM) and labelIndent: { "base": 25, "step": 17 }. options.format has no effect and warns format-unused: set measures[].format.

The report-sheet look comes from theme.overrides.table. tones: "fill" paints judged cells with grounds (good, goodStrong, warn, bad) and keeps the figures in the text ink. rows: { "lineHeight": 1.44, "pad": 3 } prints every rung at one size. weights sets the label weights of member rows and measure rows. mark: "boxed" draws a framed open and close mark. headRule: "ink" and blockRule: "rule" set the rules under the heads and around an open block. head: { "case": "asis" } keeps period heads as written (14 Sep) instead of capitals. bar sets the size bar colors, ofWhich: "ink" prints split rows in the text ink instead of the muted ink, and endRule: "none" drops the right edge rule inside a host card. The worked example uses this look; the fixture sheet and Theme show the other tokens.

A long omitted-period list names the first eight periods, then "and N more" with the exact count left out. It follows the supplied period order and uses the shared note rule, which also names a lone ninth period. The existing notes.maxListed option sets another limit: 0 draws only the count, and "all" draws every name. The reading keeps the full list in the note text. Its short field holds the text drawn in SVG and React.

Worked example

An invented web shop sells through four leaf channels: Brand search and Generic search under Paid search, Paid social, and Email. Email has no spend. The host sums daily rows into windows. Range is 14 Sep to 7 Oct 2026 (24 days), and Prior is the 24 days before it, 21 Aug to 13 Sep. The displayed periods are the ISO weeks W38 to W41. W41 runs from Monday to Wednesday, so it is partial, and its reference window is Monday to Wednesday of W40. The fields are orders, nc (new customers), rev (net revenue) and spend; no Email fact has spend.

The measures: Orders (count, judged as volume), New customers (dual-role: a root with splits off, a split of Orders with splits on), Existing customers (a split of Orders: orders − nc), New-customer share (nc / orders × 100, a pp change, judged as rate), Net revenue (money, unjudged, so it draws size bars), AOV (rev / orders, per unit, judged as volume), and the group Paid media with Marketing spend (money, unjudged) and CAC (spend / nc, judged as cost). minimumSample asks for 200 orders and 50 new customers in both windows. expansion opens the Paid search rows of Marketing spend and CAC, and the theme gives the report-sheet look of View options.

What it draws, in by-measure at depth 2 with splits off (32 rows): the section ALL CHANNELS with Orders, New customers, New-customer share, Net revenue and AOV, each followed by Paid search, Paid social and Email; then the section PAID MEDIA, CHANNELS WITH SPEND with Marketing spend and CAC, each followed by Paid search and Paid social only. Under those two measures expansion opens Paid search, so Brand search and Generic search show there; the other Paid search rows carry a closed (+) mark. Without expansion the view has 28 rows. Orders print 4,641 for Range and +7% vs prior, judged good. The CAC of Paid search climbs from 50 to 53, 58 and 62 over the four weeks, and its vs prior change of +9% is judged warn (cost, at least 5%). Under it, Generic search drives the rise (60 to 78) while Brand search stays at 39 or 40. The weekly cells of Email new customers stay neutral, because 22 a week is below the minimum sample of 50. The W41 column is muted and not judged, but its changes compare the same three days.

In by-member at depth 1 (13 rows) the same spec shows the open Total block with its seven measures, the section CHANNEL, and three folded member rows: Paid search with 61.3k (Marketing spend, USD), Paid social with 27.3k, and Email with 86.1k (Net revenue, USD), because spend does not apply to Email.

{
  "type": "dimswitch",
  "data": {
    "dimension": {
      "label": "Channel",
      "total": { "id": "total", "label": "Total", "heading": "All channels" },
      "members": [
        { "id": "search", "label": "Paid search" },
        { "id": "brand", "label": "Brand search", "parentId": "search" },
        { "id": "generic", "label": "Generic search", "parentId": "search" },
        { "id": "social", "label": "Paid social" },
        { "id": "email", "label": "Email" }
      ],
      "headline": ["spend", "revenue"]
    },
    "changeLabel": "WoW",
    "groupHeadings": { "Paid media": "Paid media, channels with spend" },
    "measures": [
      {
        "id": "orders",
        "label": "Orders",
        "value": { "field": "orders" },
        "scale": "count",
        "judge": { "family": "volume", "base": "orders" }
      },
      {
        "id": "new",
        "label": "New customers",
        "value": { "field": "nc" },
        "scale": "count",
        "splitOf": "orders",
        "judge": { "family": "volume", "base": "nc" }
      },
      {
        "id": "existing",
        "label": "Existing customers",
        "value": { "op": "sub", "a": { "field": "orders" }, "b": { "field": "nc" } },
        "scale": "count",
        "parentId": "orders"
      },
      {
        "id": "share",
        "label": "New-customer share",
        "value": { "op": "div", "a": { "field": "nc" }, "b": { "field": "orders" }, "factor": 100 },
        "scale": "percent",
        "change": "pp",
        "judge": { "family": "rate", "base": "orders" }
      },
      {
        "id": "revenue",
        "label": "Net revenue",
        "value": { "field": "rev" },
        "scale": "money",
        "unit": "USD",
        "divider": true
      },
      {
        "id": "aov",
        "label": "AOV",
        "value": { "op": "div", "a": { "field": "rev" }, "b": { "field": "orders" } },
        "scale": "perUnit",
        "unit": "USD",
        "judge": { "family": "volume", "base": "orders" }
      },
      {
        "id": "spend",
        "label": "Marketing spend",
        "value": { "field": "spend" },
        "scale": "money",
        "unit": "USD",
        "group": "Paid media"
      },
      {
        "id": "cac",
        "label": "CAC",
        "value": { "op": "div", "a": { "field": "spend" }, "b": { "field": "nc" } },
        "scale": "perUnit",
        "unit": "USD",
        "group": "Paid media",
        "judge": { "family": "cost", "base": "nc" }
      }
    ],
    "periods": [
      { "id": "range", "label": "Range", "subLabel": "14 Sep–7 Oct", "kind": "range" },
      { "id": "prior", "label": "vs prior", "subLabel": "21 Aug–13 Sep", "kind": "prior" },
      { "id": "w38", "label": "14 Sep", "subLabel": "W38" },
      { "id": "w39", "label": "21 Sep", "subLabel": "W39" },
      { "id": "w40", "label": "28 Sep", "subLabel": "W40" },
      { "id": "w41", "label": "5 Oct", "subLabel": "W41", "partial": true }
    ],
    "facts": [
      {
        "memberId": "total",
        "periodId": "range",
        "sums": { "orders": 4641, "nc": 1801, "rev": 364277, "spend": 88583 }
      },
      {
        "memberId": "search",
        "periodId": "range",
        "sums": { "orders": 2662, "nc": 1112, "rev": 208407, "spend": 61292 }
      },
      {
        "memberId": "brand",
        "periodId": "range",
        "sums": { "orders": 1469, "nc": 495, "rev": 119618, "spend": 19455 }
      },
      {
        "memberId": "generic",
        "periodId": "range",
        "sums": { "orders": 1193, "nc": 617, "rev": 88789, "spend": 41837 }
      },
      {
        "memberId": "social",
        "periodId": "range",
        "sums": { "orders": 1006, "nc": 613, "rev": 69794, "spend": 27291 }
      },
      {
        "memberId": "email",
        "periodId": "range",
        "sums": { "orders": 973, "nc": 76, "rev": 86076 }
      },
      {
        "memberId": "total",
        "periodId": "prior",
        "sums": { "orders": 4346, "nc": 1648, "rev": 342411, "spend": 80214 }
      },
      {
        "memberId": "search",
        "periodId": "prior",
        "sums": { "orders": 2555, "nc": 1062, "rev": 200070, "spend": 53475 }
      },
      {
        "memberId": "brand",
        "periodId": "prior",
        "sums": { "orders": 1439, "nc": 486, "rev": 117101, "spend": 19062 }
      },
      {
        "memberId": "generic",
        "periodId": "prior",
        "sums": { "orders": 1116, "nc": 576, "rev": 82969, "spend": 34413 }
      },
      {
        "memberId": "social",
        "periodId": "prior",
        "sums": { "orders": 837, "nc": 511, "rev": 57999, "spend": 26739 }
      },
      {
        "memberId": "email",
        "periodId": "prior",
        "sums": { "orders": 954, "nc": 75, "rev": 84342 }
      },
      {
        "memberId": "total",
        "periodId": "w38",
        "sums": { "orders": 1309, "nc": 503, "rev": 103897, "spend": 23633 },
        "ref": { "orders": 1295, "nc": 494, "rev": 102447, "spend": 23633 }
      },
      {
        "memberId": "search",
        "periodId": "w38",
        "sums": { "orders": 753, "nc": 313, "rev": 59557, "spend": 15755 },
        "ref": { "orders": 753, "nc": 313, "rev": 59277, "spend": 15755 }
      },
      {
        "memberId": "brand",
        "periodId": "w38",
        "sums": { "orders": 424, "nc": 143, "rev": 34850, "spend": 5616 },
        "ref": { "orders": 424, "nc": 143, "rev": 34688, "spend": 5616 }
      },
      {
        "memberId": "generic",
        "periodId": "w38",
        "sums": { "orders": 329, "nc": 170, "rev": 24707, "spend": 10139 },
        "ref": { "orders": 329, "nc": 170, "rev": 24589, "spend": 10139 }
      },
      {
        "memberId": "social",
        "periodId": "w38",
        "sums": { "orders": 275, "nc": 168, "rev": 19249, "spend": 7878 },
        "ref": { "orders": 261, "nc": 159, "rev": 18193, "spend": 7878 }
      },
      {
        "memberId": "email",
        "periodId": "w38",
        "sums": { "orders": 281, "nc": 22, "rev": 25091 },
        "ref": { "orders": 281, "nc": 22, "rev": 24977 }
      },
      {
        "memberId": "total",
        "periodId": "w39",
        "sums": { "orders": 1331, "nc": 515, "rev": 100799, "spend": 24799 },
        "ref": { "orders": 1309, "nc": 503, "rev": 103897, "spend": 23633 }
      },
      {
        "memberId": "search",
        "periodId": "w39",
        "sums": { "orders": 762, "nc": 317, "rev": 57554, "spend": 16921 },
        "ref": { "orders": 753, "nc": 313, "rev": 59557, "spend": 15755 }
      },
      {
        "memberId": "brand",
        "periodId": "w39",
        "sums": { "orders": 424, "nc": 143, "rev": 33301, "spend": 5616 },
        "ref": { "orders": 424, "nc": 143, "rev": 34850, "spend": 5616 }
      },
      {
        "memberId": "generic",
        "periodId": "w39",
        "sums": { "orders": 338, "nc": 174, "rev": 24253, "spend": 11305 },
        "ref": { "orders": 329, "nc": 170, "rev": 24707, "spend": 10139 }
      },
      {
        "memberId": "social",
        "periodId": "w39",
        "sums": { "orders": 288, "nc": 176, "rev": 19269, "spend": 7878 },
        "ref": { "orders": 275, "nc": 168, "rev": 19249, "spend": 7878 }
      },
      {
        "memberId": "email",
        "periodId": "w39",
        "sums": { "orders": 281, "nc": 22, "rev": 23976 },
        "ref": { "orders": 281, "nc": 22, "rev": 25091 }
      },
      {
        "memberId": "total",
        "periodId": "w40",
        "sums": { "orders": 1360, "nc": 531, "rev": 108939, "spend": 26926 },
        "ref": { "orders": 1331, "nc": 515, "rev": 100799, "spend": 24799 }
      },
      {
        "memberId": "search",
        "periodId": "w40",
        "sums": { "orders": 779, "nc": 327, "rev": 62270, "spend": 19048 },
        "ref": { "orders": 762, "nc": 317, "rev": 57554, "spend": 16921 }
      },
      {
        "memberId": "brand",
        "periodId": "w40",
        "sums": { "orders": 424, "nc": 143, "rev": 35279, "spend": 5616 },
        "ref": { "orders": 424, "nc": 143, "rev": 33301, "spend": 5616 }
      },
      {
        "memberId": "generic",
        "periodId": "w40",
        "sums": { "orders": 355, "nc": 184, "rev": 26991, "spend": 13432 },
        "ref": { "orders": 338, "nc": 174, "rev": 24253, "spend": 11305 }
      },
      {
        "memberId": "social",
        "periodId": "w40",
        "sums": { "orders": 300, "nc": 182, "rev": 21266, "spend": 7878 },
        "ref": { "orders": 288, "nc": 176, "rev": 19269, "spend": 7878 }
      },
      {
        "memberId": "email",
        "periodId": "w40",
        "sums": { "orders": 281, "nc": 22, "rev": 25403 },
        "ref": { "orders": 281, "nc": 22, "rev": 23976 }
      },
      {
        "memberId": "total",
        "periodId": "w41",
        "sums": { "orders": 641, "nc": 252, "rev": 50642, "spend": 13225 },
        "ref": { "orders": 628, "nc": 245, "rev": 49753, "spend": 12235 }
      },
      {
        "memberId": "search",
        "periodId": "w41",
        "sums": { "orders": 368, "nc": 155, "rev": 29026, "spend": 9568 },
        "ref": { "orders": 360, "nc": 151, "rev": 28461, "spend": 8578 }
      },
      {
        "memberId": "brand",
        "periodId": "w41",
        "sums": { "orders": 197, "nc": 66, "rev": 16188, "spend": 2607 },
        "ref": { "orders": 197, "nc": 66, "rev": 16208, "spend": 2607 }
      },
      {
        "memberId": "generic",
        "periodId": "w41",
        "sums": { "orders": 171, "nc": 89, "rev": 12838, "spend": 6961 },
        "ref": { "orders": 163, "nc": 85, "rev": 12253, "spend": 5971 }
      },
      {
        "memberId": "social",
        "periodId": "w41",
        "sums": { "orders": 143, "nc": 87, "rev": 10010, "spend": 3657 },
        "ref": { "orders": 138, "nc": 84, "rev": 9672, "spend": 3657 }
      },
      {
        "memberId": "email",
        "periodId": "w41",
        "sums": { "orders": 130, "nc": 10, "rev": 11606 },
        "ref": { "orders": 130, "nc": 10, "rev": 11620 }
      }
    ]
  },
  "options": {
    "title": "Orders grew 7% while paid search CAC rose every week",
    "variant": "by-measure",
    "depth": 2,
    "expansion": { "expanded": ["[\"by-measure\",\"search\",\"spend\"]", "[\"by-measure\",\"search\",\"cac\"]"] },
    "minimumSample": { "orders": 200, "nc": 50 },
    "widths": { "range": 120, "change": 120 },
    "size": { "width": 1050 },
    "theme": {
      "preset": "boardroom",
      "overrides": {
        "table": {
          "tones": "fill",
          "rows": { "lineHeight": 1.44, "pad": 3 },
          "weights": { "member": 700, "measure": 600 },
          "mark": "boxed",
          "headRule": "ink",
          "blockRule": "rule",
          "head": { "case": "asis" }
        }
      }
    }
  }
}

React usage

DimSwitchChart from boardplot/react/dimswitch takes data and every option as its own prop; it has no options prop. The type DimSwitchData comes from boardplot, and the types DimSwitchView and DimSwitchViewReason come from the component entry.

The component draws no switches. The host draws the Variant, Depth, Splits and Changes controls and passes their values as the props variant, depth, splits and inlineVisibility={{ change }}. variant, depth, splits and collapsed each have a default... twin, which sets the start value when the host does not control the prop. An uncontrolled variant, depth or splits never changes after the first render, because the component has no control for it. Offer depth values from 1 to the number of member levels plus one; a higher depth throws.

onViewChange(next, reason) reports the view { variant, depth, splits, collapsed } after each change. The reason collapsed means that the reader opened or folded a row. The reasons variant, depth and splits mean that the prop changed; next.collapsed then holds the folds that apply now. Pass onViewChange={setView} to keep one view state.

A change of variant or depth resets the manual folds to the depth defaults, with expansion on top. A change of splits or of the Changes switch keeps the manual folds. Control collapsed only to restore a saved view, and then store next.collapsed from every onViewChange call. Do not start it with []: an empty list opens every row. Leave it undefined, or pass the saved list.

The TableChart host props pass through: size="container" with fallbackSize, fit, fillHeight, stickyLabels, rowExtent, cellPadX, fontMetrics, measureWidths, hover, onRowSelect, handleRef and onScrollChange. toolbar is false by default. isRowSelectable(row, { collapsed }) also passes through; collapsed is true while the row is folded shut. mountCollapsed is false by default here, so the browser paints a leaf row only near the viewport; to capture a whole long table, set paintOffscreenRows: true. See React.

Speed: the component compiles the cube again only when data, variant, splits or another option changes. depth, collapsed and the Changes switch change only the folds or the CSS, so they are fast. The component compares data by content: keep it the same object while it does not change (useMemo), because a deep compare of a large cube also takes time. Closed rows are not mounted, so the cost grows with the open rows times the period columns. Rows that open fade and slide in over the theme duration motion.layout (160 ms by default), and rows that close go at once; motion: "reduce" on BoardplotTheme, or the reader setting for reduced motion, turns this off. In one development measurement, opening 350 rows with 60 period columns took about 0.6 s. A Day grain over a long range gives one column for each day: offer Day only for short ranges, and use Week or Month for longer ones.

This host component maps query rows to facts (see Host data) and draws the four controls. Its Range is W40 and the running W41 (Monday to Wednesday); Prior is the 10 days before.

import { useMemo, useState } from 'react';
import { DimSwitchChart, type DimSwitchView } from 'boardplot/react/dimswitch';
import type { DimSwitchData, DimSwitchSums } from 'boardplot';

// Query result rows: member, period, orders, nc, spend, ref_orders, ref_nc, ref_spend.
type Row = [string, string, ...(number | null)[]];
const ROWS: Row[] = [
  ['total', 'range', 1445, 474, 22600, null, null, null], ['total', 'prior', 1402, 453, 20700, null, null, null],
  ['total', 'w40', 990, 322, 15400, 968, 315, 14400], ['total', 'w41', 455, 152, 7200, 451, 148, 6750],
  ['search', 'range', 1040, 442, 22600, null, null, null], ['search', 'prior', 1000, 422, 20700, null, null, null],
  ['search', 'w40', 710, 300, 15400, 692, 294, 14400], ['search', 'w41', 330, 142, 7200, 321, 137, 6750],
  ['brand', 'range', 600, 206, 8100, null, null, null], ['brand', 'prior', 580, 196, 7900, null, null, null],
  ['brand', 'w40', 410, 140, 5600, 402, 136, 5500], ['brand', 'w41', 190, 66, 2500, 185, 63, 2450],
  ['generic', 'range', 440, 236, 14500, null, null, null], ['generic', 'prior', 420, 226, 12800, null, null, null],
  ['generic', 'w40', 300, 160, 9800, 290, 158, 8900], ['generic', 'w41', 140, 76, 4700, 136, 74, 4300],
  ['email', 'range', 405, 32, null, null, null, null], ['email', 'prior', 402, 31, null, null, null, null],
  ['email', 'w40', 280, 22, null, 276, 21, null], ['email', 'w41', 125, 10, null, 130, 11, null],
];
const FIELDS = ['orders', 'nc', 'spend'];
// Decided on the whole source, not on the selected range: Email never has spend.
const WITHOUT_SPEND = new Set(['email']);

function sums(member: string, values: (number | null)[]): DimSwitchSums {
  const out: DimSwitchSums = {};
  FIELDS.forEach((field, index) => {
    if (field === 'spend' && WITHOUT_SPEND.has(member)) return; // Absent: spend and CAC do not apply.
    out[field] = values[index] ?? 0; // A window without activity is 0, not missing.
  });
  return out;
}

function toCube(rows: Row[]): DimSwitchData {
  return {
    dimension: {
      label: 'Channel',
      total: { id: 'total', label: 'Total' },
      members: [
        { id: 'search', label: 'Paid search' },
        { id: 'brand', label: 'Brand search', parentId: 'search' },
        { id: 'generic', label: 'Generic search', parentId: 'search' },
        { id: 'email', label: 'Email' },
      ],
      headline: ['spend', 'orders'],
    },
    changeLabel: 'WoW',
    measures: [
      { id: 'orders', label: 'Orders', value: { field: 'orders' }, scale: 'count', judge: { family: 'volume', base: 'orders' } },
      { id: 'new', label: 'New customers', value: { field: 'nc' }, scale: 'count', splitOf: 'orders', judge: { family: 'volume', base: 'nc' } },
      { id: 'spend', label: 'Marketing spend', value: { field: 'spend' }, scale: 'money', unit: 'USD', divider: true },
      { id: 'cac', label: 'CAC', value: { op: 'div', a: { field: 'spend' }, b: { field: 'nc' } }, scale: 'perUnit', unit: 'USD', judge: { family: 'cost', base: 'nc' } },
    ],
    periods: [
      { id: 'range', label: 'Range', subLabel: '28 Sep–7 Oct', kind: 'range' },
      { id: 'prior', label: 'vs prior', subLabel: '18–27 Sep', kind: 'prior' },
      { id: 'w40', label: '28 Sep', subLabel: 'W40' },
      { id: 'w41', label: '5 Oct', subLabel: 'W41', partial: true },
    ],
    facts: rows.map(([member, period, ...values]) => ({
      memberId: member,
      periodId: period,
      sums: sums(member, values.slice(0, 3)),
      ...(period === 'range' || period === 'prior' ? {} : { ref: sums(member, values.slice(3)) }),
    })),
  };
}

export function ChannelTable() {
  const data = useMemo(() => toCube(ROWS), []);
  // view.collapsed is not passed back: the component keeps the manual folds.
  const [view, setView] = useState<DimSwitchView>({ variant: 'by-measure', depth: 1, splits: false, collapsed: [] });
  const [changes, setChanges] = useState(true);
  const pick = (next: Partial<DimSwitchView>) => setView({ ...view, ...next });
  return (
    <section>
      <div role="toolbar" aria-label="Table view">
        <button type="button" aria-pressed={view.variant === 'by-measure'} onClick={() => pick({ variant: 'by-measure' })}>By KPI</button>
        <button type="button" aria-pressed={view.variant === 'by-member'} onClick={() => pick({ variant: 'by-member' })}>By channel</button>
        {[1, 2, 3].map((depth) => (
          <button key={depth} type="button" aria-pressed={view.depth === depth} onClick={() => pick({ depth })}>Depth {depth}</button>
        ))}
        <button type="button" aria-pressed={view.splits} onClick={() => pick({ splits: !view.splits })}>Splits</button>
        <button type="button" aria-pressed={changes} onClick={() => setChanges(!changes)}>Changes</button>
      </div>
      <DimSwitchChart
        data={data}
        variant={view.variant}
        depth={view.depth}
        splits={view.splits}
        onViewChange={setView}
        inlineVisibility={{ change: changes }}
        minimumSample={{ nc: 50 }}
        title={false}
        size="container"
        fallbackSize={{ width: 960, height: 480 }}
      />
    </section>
  );
}

Common mistakes

Each item names the mistake, the symptom and the fix.

Sizing

Floor 280 × 80 px; fit content.

Below the floor a render is refused with size-below-floor and the pixels it needs. measure returns the natural and comfortable size for a given spec; see Sizing in the manual.

Fixtures

IDKindUse case
by-measureexampleKPIs and their channel members
by-memberexampleChannels and their KPIs
periods-onlyexampleKPIs by period without the Range and vs prior columns
range-onlyexampleKPIs with the Range column alone
column-overridesexampleKPIs with authored head text, track widths and alignment
periods-firstexampleKPIs with the periods before the Range block
sheetexampleKPIs on the report sheet
statementexampleA contribution-margin statement per order
statement-channelsexampleThe statement with the channels folded under the Total
statement-operatorsexampleThe statement by channel with operators
statement-plainexampleThe statement as supplied, Total folded
statement-ink-onlyexampleThe statement with driver ink only, no group ground and the old frame
statement-all-tonesexampleThe statement with every driver tone, a group ground that stays when folded and a page-pinned head
total-rate-liftexampleMember rate relative to the Total rate
bands-and-planexampleValue bands with separate prior and plan changes
thresholds-by-kindexampleSeparate thresholds for each change kind
multiple-sample-basesexampleJudge only when both sample fields pass
no-barsexampleKPIs without the automatic size bars
no-total-blockexampleChannels and their KPIs without the Total block
total-row-blankexampleKPIs over their members with blank Total cells
total-bottomexampleChannels and their KPIs with the Total block last
no-group-headsexampleKPIs without their section heads
no-group-heads-by-memberexampleChannels with grouped KPIs and no group label rows
card-notes-detortureGerman engine notes on a phone card

Not for

Two dimensions at once, such as channel by country, or a plain list of rows: use table. One KPI over time: use line or kpi. Calendar logic: the host computes the windows and their sums, and boardplot does no date arithmetic.