# The numbers come from the data

A report declares its sources under `data:` in its front matter: a CSV, JSON or YAML file next to
the story, or rows written inline. The build reads them in Node, infers the type of each column, and
renders four directives. The rows never reach the browser: only the numbers shown do.

```yaml
data:
  sales: ./data/sales.csv
  regions: ./data/regions.json
  targets: ./data/targets.yaml
```

## A number in a sentence

`:value` computes one number. `agg` has no default, so no number is ever chosen implicitly.

```md
Revenue reached :value{data=sales field=revenue agg=sum format=currency currency=EUR}, and moved
by :value{data=sales field=revenue agg=growth by=month period=quarter} over the previous quarter.
```

Computed by this page, from the data of the quarterly report: revenue reached :value{data=sales field=revenue agg=sum format=currency currency=EUR}, and moved by :value{data=sales field=revenue agg=growth by=month period=quarter} over the previous quarter.

`growth` compares the last complete period with the one before it. The result is a `<data>` element:
its `value` holds the exact number, its text the number in the words of the story's language.

## A chart

`::chart` names columns, never values. It is drawn as SVG during the build, with the accessible
palette and colour roles of the theme, and a "Data" disclosure under it shows the table of the
points it plots.

```md
::chart{data=sales type=line x=month y=revenue color=region title="Monthly revenue by region"}
```

::chart{data=sales type=line x=month y=revenue color=region title="Monthly revenue by region"}

## A table and key figures

```md
::table{data=regions columns="name,revenue,growth" sort=-revenue format="revenue=currency,growth=percent" currency=EUR rename="name=Region,growth=Growth" caption="Revenue by region"}

:::kpi
- :value{data=sales field=revenue agg=sum format=compact} Revenue
- :value{data=sales field=orders agg=sum} Orders
:::
```

::table{data=regions columns="name,revenue,growth" sort=-revenue format="revenue=currency,growth=percent" currency=EUR rename="name=Region,growth=Growth" caption="Revenue by region"}

:::kpi
- :value{data=sales field=revenue agg=sum format=compact} Revenue
- :value{data=sales field=orders agg=sum} Orders
:::

## Markdown and its JSON twin

Every report has a typed JSON twin (`kind: "story"`), validated by `report.json` and convertible
both ways with `recit convert`. The twin points to the same data files without copying their rows,
and compiles to the same HTML:

<CodeTabs>

```md title="quarterly.story.md"
---
title: Lorem Ipsum Quarterly
format: report
lang: en
date: 2026-12-31
data:
  sales: ./data/sales.csv
  regions:
    src: ./data/regions.json
    columns: { name: string, revenue: number, growth: number }
toc: true
---

--- id=summary

## Summary

Revenue reached :value{data=sales field=revenue agg=sum where="month=2026-12" format=currency currency=EUR}.

::chart{data=sales type=line x=month y=revenue color=region title="Monthly revenue by region"}
```

```json title="quarterly.story.json"
{
  "$schema": "https://recit.dev/schema/v1/report.json",
  "kind": "story",
  "version": 1,
  "format": "report",
  "meta": {
    "title": "Lorem Ipsum Quarterly",
    "date": "2026-12-31",
    "lang": "en"
  },
  "data": {
    "sales": "./data/sales.csv",
    "regions": {
      "src": "./data/regions.json",
      "columns": { "name": "string", "revenue": "number", "growth": "number" }
    }
  },
  "settings": { "toc": true },
  "scenes": [
    {
      "id": "summary",
      "body": "## Summary\n\nRevenue reached :value{data=sales field=revenue agg=sum where=\"month=2026-12\" format=currency currency=EUR}.\n\n::chart{data=sales type=line x=month y=revenue color=region title=\"Monthly revenue by region\"}"
    }
  ]
}
```

</CodeTabs>

## An error, with its line

A field, a source or an attribute that does not exist stops the build, with the line and the closest
name:

```text
report.md:12 :value: field "revnue" not in sales (did you mean "revenue"?)
```

The whole report these fragments come from is in the [gallery](/report/gallery).
