Skip to contentSheetwrite

Analysis

A dashboard that filters together

Filter a dashboard of KPI cards, a PivotChart and a pivot with its slicers, then move, resize and add items. Undo takes back each change.

Orders
200
Items
0
Layout
Twelve-column grid
Try it
  1. Region: Every region
  2. 0 items
  3. Arrange by handDrag an item's header to move it, or its corner to resize it.

How a dashboard works

  • A dashboard is a sheet with kind: "dashboard". Its pivots compute from the Orders table without writing output cells.
  • A slicer filters every pivot, PivotChart and KPI card whose table reaches its column, as an Excel slicer filters its connected PivotTables. Its selection is saved and undone.
  • A KPI card shows a data model measure in the slicers' filter context. Items never overlap: a move or resize into another item's place is refused, and the view says so.
How a dashboard filters togetherA dashboard sheet's pivots compute from the Orders table without writing output cells. One slicer on Region filters every pivot, PivotChart and KPI card whose table reaches its column, and its selection is saved and undone. A KPI card shows a data model measure in the slicers' filter context.Slicer: RegionFilters each item whose tablereaches the Region columnPivotComputes from Orders,no output cellsPivotChartFiltered with its pivotKPI cardA measure in theslicers' filter context
How a dashboard filters togetherA dashboard sheet's pivots compute from the Orders table without writing output cells. One slicer on Region filters every pivot, PivotChart and KPI card whose table reaches its column, and its selection is saved and undone. A KPI card shows a data model measure in the slicers' filter context.Slicer: RegionFilters each item whose tablereaches the Region columnPivotComputes from Orders,no output cellsPivotChartFiltered with its pivotKPI cardA measure in theslicers' filter context

The pivots compute from the Orders table; the slicer's selection is saved and undone.

The code behind it

dashboards.ts
import "@sheetwrite/core/styles.css";
import { createGrid, initSheetwrite, type DashboardItem, type Workbook } from "@sheetwrite/core";
// An "orders" table with a Region column (B) and a Revenue column (E)
declare const workbook: Workbook;
// Pivots and measures need the full engine
await initSheetwrite({ engine: await import("@sheetwrite/formulas") });
// The grid fills its host, so the host needs a height
const host = document.querySelector<HTMLElement>("#grid");
if (host === null) throw new Error("Missing #grid host");
host.style.height = "480px";
const grid = createGrid(host, { workbook });
// A dashboard sheet lays out pivots, charts, KPI cards and slicers on twelve columns
grid.addSheet({ id: "dashboard", name: "Sales dashboard", kind: "dashboard" });
{
id: "by-region",
name: "Revenue by region",
source: { table: "orders" },
anchor: { row: 0, col: 0 },
rows: [1],
columns: [],
values: [{ field: 4, aggregation: "SUM", name: "Revenue" }],
},
"dashboard",
);
const items: DashboardItem[] = [
// A KPI card shows a data model measure, defined below
{ id: "revenue-kpi", kind: "kpi", measure: "revenue", box: { x: 0, y: 0, w: 3, h: 3 } },
{ id: "region-pivot", kind: "pivot", pivot: "by-region", box: { x: 0, y: 3, w: 6, h: 6 } },
// The slicer filters the KPI card and the pivot together
{
id: "region-slicer",
kind: "slicer",
field: { table: "orders", column: "region" },
selected: ["EMEA"],
box: { x: 6, y: 0, w: 3, h: 3 },
},
];
// The measure and the items in one transaction: one undo step, saved and synced
// with the workbook
{
op: "setMeasure",
measure: { id: "revenue", name: "Revenue", table: "orders", formula: "=SUM(Orders[Revenue])" },
},
...items.map((item) => ({ op: "setDashboardItem" as const, sheet: "dashboard", item })),
],
});
// When the page removes the host: grid.destroy();
Show all 56 linesShow the first lines