Calculated Values
An aggregation combines records, such as adding sales. A calculation transforms that summary, such as comparing this quarter’s sales with the previous quarter.
Start with aggregations. For shares of a total, use the focused percentages guide and its live example.
Try running totals and comparisons
Section titled “Try running totals and comparisons”Compare quarterly sales
Calculate a running total or compare each quarter with the previous one.
Try it: Choose Running total, compare Change from previous quarter, then return to Quarterly sales.
What to notice: Q1 sales are $400 and Q2 sales are $600. The running total reaches $1,000; Q2 increased by $200.
The report starts with Q1 $400 and Q2 $600. Choose Running total to see Q2 become $1,000. Choose Change from previous quarter to see Q2’s increase of $200; Q1 has no previous quarter to compare. Quarterly sales restores the original amounts.
Choose a calculation
Section titled “Choose a calculation”| Question | Calculation |
|---|---|
| What share of sales belongs to each region? | Percentages |
| How much have we sold so far? | Running total |
| How much did sales change from the previous period? | Difference or percentage difference |
| Which group ranks first? | Rank |
| How do two configured measures combine? | Formula |
Add a running total
Section titled “Add a running total”import type { PivotConfig } from '@revolist/pivot';
const config: PivotConfig = { rows: ['quarter'], columns: [], values: [{ id: 'cumulative-sales', prop: 'sales', aggregator: 'sum', label: 'Sales to date', calculation: { type: 'runningTotal', axis: 'rows', field: 'quarter' }, format: { preset: 'currency', currency: 'USD', locale: 'en-US' }, }], totals: { grandTotal: false },};grid.pivot = config;Here grid is the grid from Your First Pivot. Quarters are on rows in this example, so the calculation uses axis: 'rows'. If your report puts quarters on columns instead, use axis: 'columns'. Use the period field on the named axis. Establish the intended order before calculating a sequence; changing display labels does not define a business calendar. The analytical semantics example explains sequences and comparison scopes.
Compare with the previous period
Section titled “Compare with the previous period”import type { PivotConfigValue } from '@revolist/pivot';
const calculation: PivotConfigValue['calculation'] = { type: 'differenceFrom', axis: 'rows', field: 'quarter', base: 'previous',};Set a measure’s calculation to this configuration to compare adjacent quarters. The first period has no previous value, so its comparison can be missing. Do not replace missing comparisons with zero unless that is the meaning your report intends.
Formula measures
Section titled “Formula measures”Give source measures stable IDs and reference those IDs in the formula expression. By default, references read the measure’s underlying aggregate; referenceValues: 'calculated' uses calculated values. See the complete formula example, including unknown references and cycle handling.
For a calculated source field, such as sales - cost before aggregation, use a V2 derived field instead. This differs from transforming an already aggregated measure; see portable report fields.
Server-side and accuracy
Section titled “Server-side and accuracy”A backend must advertise and implement the requested calculation profile. The adapter guide explains capability admission. Number formats do not increase arithmetic precision; inspect numeric policies when defining financial or statistical reports.
Next steps
Section titled “Next steps”Show multiple measures, rank groups, or use the resulting measures in a chart.