Birch UI v0.1
Pricing

CalculationsPivot Studio

Summarize values with sum, count, average, min, max, distinct count and median, and show them as percentages of totals, running totals or differences from the previous member.

Open .md

Every field in the Values zone becomes a measure: an aggregation of the field, optionally shown as a calculation over other cells, such as a percentage of the column total.

TypeScript
const report: PivotReport = {
  slice: {
    rows: [{ field: 'region' }, { field: 'store' }],
    columns: [{ field: 'orderDate.quarter' }],
    values: [
      { field: 'revenue' },
      { field: 'revenue', showAs: 'percentOfColumnTotal', caption: 'Share of quarter' },
      { field: 'orderId', aggregation: 'distinctCount', caption: 'Orders' },
      { field: 'units', aggregation: 'median', caption: 'Median basket size' },
    ],
  },
};
ValueFieldinterface@birchui/pivot-studioFull reference
PropertyTypeDescription
fieldstring—
aggregationoptionalAggregationName—
showAsoptionalShowValuesAs—
alongoptionalPivotAxis—
captionoptionalstring—
formatoptionalPivotNumberFormat—
idoptionalstring—

Aggregations#

aggregation Label Result
sum Sum Total of the values
count Count Number of non-blank values
avg Average Mean of the non-blank values
min Min Smallest value
max Max Largest value
distinctCount Distinct count Number of different values, for example distinct orders or customers
median Median Middle value of the non-blank values

Which aggregations a field offers depends on its type:

Field type Aggregations Default
number sum, count, avg, min, max, distinctCount, median sum
date count, distinctCount, min, max count
boolean count, distinctCount, sum, avg count
string count, distinctCount count

For booleans, sum counts the true values and avg gives the share of true values, for example the share of orders with a promotion. Min and max of a date field are shown as dates. An aggregation a field does not support falls back to its default.

Change a measure's aggregation from the value chip's Summarize by menu, or from code:

TypeScript
studio.setAggregation('sum(units)', 'avg');

Totals are exact#

Subtotals and grand totals are aggregated from the underlying records, not from the cells above them. An average in a total row is the average of all records in that group, a median is the true median, and a distinct count counts each customer once even when they bought in several stores.

Measure IDs#

Measures are identified by an ID that reports, sorting, filters, conditional formats and events use:

Value field ID
{ field: 'revenue' } sum(revenue)
{ field: 'units', aggregation: 'avg' } avg(units)
{ field: 'revenue', showAs: 'percentOfGrandTotal' } sum(revenue):percentOfGrandTotal
{ field: 'orderId', aggregation: 'distinctCount' } distinctCount(orderId)
{ field: 'margin', id: 'grossMargin' } grossMargin

When two value fields would get the same ID, the second gets a #2 suffix. Set id yourself when other code refers to a measure, so the reference survives users changing its aggregation.

Captions#

Without a caption, a measure is named after its field when it uses the field's default aggregation ("Revenue"), and after both otherwise ("Average of Units", "Distinct count of Order id"). A calculation is added in parentheses: "Revenue (% of grand total)", "Revenue (running total across columns)".

Show values as#

showAs turns each cell into a calculation over other cells:

showAs Each cell shows Typical question
none (default) The aggregated value How much did each store sell?
percentOfGrandTotal Its share of the grand total Which stores bring in most of the revenue?
percentOfRowTotal Its share of its row's total How is each store's revenue split across quarters?
percentOfColumnTotal Its share of its column's total What share of Q2 revenue came from each store?
percentOfParentRowTotal Its share of its parent row What share of the North region does each store contribute?
percentOfParentColumnTotal Its share of its parent column What share of the year does each quarter contribute?
runningTotal The cumulative total so far Year-to-date revenue by month
differenceFromPrevious The value minus the previous member's How much did revenue change from last month?
percentDifferenceFromPrevious The change relative to the previous member By what percentage did units change from last quarter?

For top-level members the parent is the grand total, so the parent percentages match the percentage of the grand total there; the grand total itself shows 100%.

Direction: along#

Running totals and differences run in one direction, set with along:

along Direction
'rows' (default) Down the rows: each row is compared with the row above it in the same group
'columns' Across the columns: each column is compared with the column to its left
TypeScript
studio.setShowValuesAs('sum(revenue)', 'runningTotal', 'columns');
studio.setShowValuesAs('sum(units)', 'percentDifferenceFromPrevious', 'rows');
studio.setShowValuesAs('sum(revenue):runningTotal', 'none');

The value chip's Show values as menu offers every option, with separate entries for rows and columns ("Running total down rows", "Running total across columns", "Difference from previous row" and so on).

The first member in each direction has no previous member, so differences show an empty cell there. For running totals, the grand total shows the plain total.

Percentages are formatted as percentages automatically. Set a number format on the value to control decimals.

A margin analysis report#

margin-report.ts
studio.setReport({
  slice: {
    rows: [{ field: 'category', sortBy: { measure: 'sum(margin)', dir: 'desc' } }, { field: 'product' }],
    columns: [{ field: 'orderDate.month' }],
    values: [
      { field: 'margin', format: { style: 'currency', currency: 'GBP', decimals: 0 } },
      { field: 'margin', id: 'marginGrowth', showAs: 'percentDifferenceFromPrevious', along: 'columns', caption: 'Change vs previous month' },
    ],
    filters: [{ field: 'orderDate.year' }],
  },
  filters: { 'orderDate.year': { include: ['2026'] } },
});

↑ ↓ to move, Enter to open, Esc to close