Demo · real data
A sales report your users can rearrange
The best sellers of 2011 in each of the top countries, with units, average price and share of the year. Drag a field to change the question, save the result as a view, click a value to see the invoice lines behind it.
Built with the free PivotGrid, Community edition.
What this report shows
The eight countries with the most revenue in 2011 and, inside each, its five best-selling products. Next to each one: revenue, units, the average price paid and the share of the year's revenue. The data is the Online Retail II dataset, 1,067,371 invoice lines from a UK online shop between December 2009 and December 2011 (UCI Machine Learning Repository, CC BY 4.0), downloaded once and computed in your browser.
Revenue is net: cancelled orders stay in and subtract, so an order cancelled the same day does not show up as a best seller. Lines that are not products, such as postage, marketplace fees and bank charges, are removed before anything is summed. Without that, postage would be the best seller in the United Kingdom.
A report your users can change
A fixed report answers one question, and the next one turns into a request to the developer. Here the report is a pivot table, so the reader changes the question: drag Month into the columns to see the year by month, take Year out to compare 2010 with 2011, or filter Kind to see only cancellations. The layout can be saved under a name and opened again later.
Click any value and the panel under the report lists the invoice lines behind it, largest first. Their revenue is added up next to the value in the cell, so you can check the two match, and the panel shows how long the grid took to find them.
How it is built
Every part of this report is a field option of the free Community edition of PivotGrid. Nothing on this page needs a licence key:
- Top N:
topN: 8on Country andtopN: 5on Product, each sorted by revenue withsortBySummaryField. - Average price: a calculated field, Revenue divided by Units, worked out after the rows are added up. Averaging the line prices instead would give a one-unit line the same weight as a pallet.
- Share of the year: the same revenue again with
summaryDisplayMode: 'percentOfColumnTotal'. - Only 2011: a filter set in code that the reader can see and change in the filter area.
- Not products: a prefilter, which removes rows before they are aggregated.
- The lines behind a value: the
recordsof the cell inonCellClick.
import { BasePivotGrid, type PivotField } from '@kanunilabs/pivotgrid-react';
import '@kanunilabs/pivotgrid-react/styles.css';
const fields: PivotField<Line>[] = [
{ id: 'country', dataField: 'country', caption: 'Country', dataType: 'string', area: 'row',
sortOrder: 'desc', sortBySummaryField: 'revenue', topN: 8 },
{ id: 'product', dataField: 'description', caption: 'Product', dataType: 'string', area: 'row',
sortOrder: 'desc', sortBySummaryField: 'revenue', topN: 5 },
{ id: 'revenue', dataField: 'revenue', caption: 'Revenue', dataType: 'number', area: 'data', summaryType: 'sum' },
{ id: 'share', dataField: 'revenue', caption: 'Share of year', dataType: 'number', area: 'data',
summaryType: 'sum', summaryDisplayMode: 'percentOfColumnTotal' },
{ id: 'year', dataField: 'year', caption: 'Year', dataType: 'string', area: 'filter',
filterValues: new Set(['2011']), filterType: 'include' },
];
<BasePivotGrid
gridId="best-sellers"
data={lines}
initialFields={fields}
onCellClick={(e) => showLines(e.records ?? [])}
/>The calculated fields guide covers the average price, and the prefilter guide the rows that are left out.
Where to next
- Drag a million rows, measured →The same data with every recompute timed in your browser, against a plain loop.
- PivotGrid in React →Install, fields, formats and localisation, step by step.
- PivotGrid playground →Every feature as a live demo you can edit, free and paid.
- PivotGrid overview →What is free, what is paid, and the full feature list.