Build a data-driven report

Build reports with DocStudio: KPI tiles from aggregates, tables with computed flags, repeaters for lists, running headers and multi-page output.

Two examples show report patterns: the business report and the laboratory report.

KPI tiles from aggregates

Outside a table, give an aggregate the list and the per-item expression explicitly:

{
  "fn": "sum",
  "args": [{ "path": "regions" }],
  "of": { "path": "revenue" }
}

avg and count work the same way. Do not use $rows here: it exists only inside a table.

Computed flags

A table cell can be any expression. The laboratory report flags a result against its reference range:

{
  "fn": "if",
  "args": [
    { "fn": "lt", "args": [{ "path": "value" }, { "path": "low" }] },
    "Low",
    {
      "fn": "if",
      "args": [{ "fn": "gt", "args": [{ "path": "value" }, { "path": "high" }] }, "High", "Normal"]
    }
  ]
}

The flag follows the numbers in your data, so it cannot disagree with them.

Lists with a repeater

Use a repeater for non-tabular lists. Inside it, paths start at the current item, and empty holds what to show for an empty list:

{
  "id": "highlights",
  "type": "repeater",
  "source": { "path": "highlights" },
  "as": "item",
  "empty": [{ "id": "none", "type": "text", "content": ["No highlights"] }],
  "children": [{ "id": "line", "type": "text", "content": [{ "path": "text" }] }]
}

Multi-page reports

Put the report name in page.header, Page {n} of {total} in page.footer, and set repeatHeader on long tables. See pagination.

Conditional emphasis

Use styleWhen to change a style from data, for example a red amount when a value is late:

{
  "styleWhen": [
    {
      "when": { "fn": "gt", "args": [{ "path": "daysOverdue" }, 30] },
      "style": { "color": "#b42318" }
    }
  ]
}

Last updated 2026-12-03