# Analytics queries A console program that uses `TAtlasAnalytics` directly, without a report definition or a dashboard: it projects and filters a `TAtlasTable` with `Select`, groups it with `Aggregate`, shows how missing values and the source table's own filter affect the results, catches the two exception classes and exports the version 1 dataset JSON that the web example reads. ## What it demonstrates - `TAtlasAnalytics.Select` with a field list and typed, conjunctive filters (`afGreater` on a numeric field, `afContains` on a text field, case-insensitive equality). - `TAtlasAnalytics.Aggregate` with two dimensions, and ungrouped with an average that skips a missing value while the count still includes the row. - `TAtlasAnalytics.FieldIndex` to find a column by name without regard to case. - Queries reading the source's current view (`TAtlasTable.SetFilter`) and never modifying it. - `EAtlasAnalyticsError` for an unknown field and `EAtlasDataError` for a filter value that does not fit the column kind. - `TAtlasAnalytics.DatasetJSON` output: numbers as JSON numbers, missing values as `null`. ## Build and run Open `AnalyticsQueries.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 ``` Sales above 10000: 3 rows, 2 columns Desktop sales in regions containing "e": 2 rows East Desktop 18000 1 West Desktop 22500 1 East Service 6400 1 North Desktop 12000 1 West Service 9600 1 North Service 4800 1 Average revenue 12216.6666666667 over 7 rows Rejected: Unknown field: Margin Rejected: Invalid finite number: lots Dataset JSON: {"version":1,"fields":[{"name":"Region","kind":"text"},{"name":"Product","kind":"text"},{"name":"Revenue","kind":"number"},{"name":"Units","kind":"number"}],"rows":[["East","Desktop",18000.0,12.0],["West","Desktop",22500.0,15.0],["East","Service",6400.0,8.0],["North","Desktop",12000.0,8.0],["West","Service",9600.0,12.0],["North","Service",4800.0,6.0],["East","Service",null,1.0]]} PASS ``` Numbers are written as JSON numbers with a decimal point (`18000.0`), and the empty revenue cell of the last row is `null`. The exit code is 0; any mismatch prints `Check failed: ...` and exits with 1. ## Adapting it Replace the `AddColumn`/`AddRow` calls with your own table (or `ImportCSV` of a file) and change the field names in the filters and measures. Every measure except `amCount` needs an `ackNumber` column.