# Grouped report to HTML
The Atlas Analytics quick start and the project of the
[tutorial](https://youseful.software/delphi/atlas-analytics.html#tutorial). A
console program builds a small sales table, defines a grouped
`TAtlasReportDefinition`, runs it, writes the HTML export next to the executable,
round-trips the definition through JSON and prepares a paginated print
document. No window is shown.
## What it demonstrates
- `GroupBy` with sum, average and count measures over one dimension, and
`Execute` returning a caller-owned `TAtlasTable`.
- `SetFilters` narrowing the rows before grouping while the source table stays
unchanged.
- `RenderHTML` producing a complete, escaped page (title, column headers,
right-aligned numeric cells, a row count).
- `ToJSON`/`LoadJSON` round trip of the definition.
- `PreparePrint` returning a `TAtlasPrintDocument` with one page.
- `SelectFields` turning the same definition into a detail report.
## Build and run
Open `GroupedReport.dpr` in Delphi 13; the IDE creates the project file. Add the Atlas Analytics `src` folder and the Atlas VCL `src` folder to the project's search path, then build and run for Win32 or Win64. No packages need to be installed. The program needs no input. It checks its own results and stops with an error if any of them differs from the output below.
## Expected output
```
Grouped report: 3 rows, 5 columns
East revenue 24400 units 20 average 12200 orders 2
West revenue 32100 units 27 average 16050 orders 2
North revenue 16800 units 14 average 8400 orders 2
Wrote ...\GroupedReport\sales-by-region.html (1453 characters)
Definition: {"version":1,"title":"Sales by region","subtitle":"Revenue, units and average sale per region","fields":[],"dimensions":["Region"],"measures":[{"field":"Revenue","caption":"Revenue","kind":1},{"field":"Units","caption":"Units","kind":1},{"field":"Revenue","caption":"Average sale","kind":4},{"field":"","caption":"Orders","kind":0}],"filters":[]}
Print document: 1 page, title "Sales by region"
Detail report: 3 Desktop rows
PASS
```
Open `sales-by-region.html` in a browser to see the report. The exit code is 0;
any mismatch prints `Check failed: ...` and exits with 1.
## Adapting it
Change `SalesTable` to load your own data (`ImportCSV` accepts a CSV string
whose header matches the columns), then change the dimension and measures in
`GroupBy`. Every measure except `amCount` needs an `ackNumber` column, and every
result column (dimensions and measure captions) needs a distinct name.