aggregate_records
Computes counts, sums, averages, minimums, and maximums over Dataverse records, optionally filtered and grouped by columns or date parts, without reading the records themselves.
Instructions
Count, sum, average, or take the minimum or maximum of records of one table (entity set), optionally grouped by columns and by parts of a date, computed by Dataverse; only reads. Use it instead of reading records with query_records to count or add them up. Returns { rows: [...] }: one row per group, holding every group's and aggregate's as, ordered by order. A value that is missing is null: a group of rows where the column is empty, or an aggregate over no non-null values (count gives 0). A group by a lookup, a choice or a yes/no column also has _label, the record's name or the choice's label (null for the empty group). A date grouping gives a part of the date as a number, not a period: month is 1 to 12, week the week of the year, quarter the quarter of the fiscal year, day the day of the month; so month, quarter and week are refused unless the same column is also grouped by year, and day unless by year and month. Weeks are counted from 1 January, so the week around the new year is split into two groups, the last week of one year and week 1 of the next; for whole weeks, filter by dates. year is the calendar year: with a fiscal year that does not start on a calendar quarter, one year and quarter group can hold the ends of two fiscal quarters, so group by year and month instead. The parts are in the time zone of the user the call runs as, the one that user sees in Dynamics. Only rows that user may read are counted. Dataverse computes totals over at most 50,000 rows: a query that matches more is an error, to be narrowed by the filter, for example to a date range. One page of groups comes back, 5000 (500 on an elastic table): a query with more groups is an error, to be narrowed by the filter or by coarser groups. A Money column is summed as stored, in each record's currency: over records in several currencies, aggregate its _base instead, in the base currency, or group by transactioncurrencyid. countcolumn does not work on a Money column; use count with a not-null filter on it. An unknown entity set or column is an error.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"entity_set": "<entity_set>",
"aggregates": "<aggregates>"
},
"name": "aggregate_records"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| order | No | The order of the result rows | |
| filter | No | Conditions on the rows counted, combined with 'and' | |
| group_by | No | Columns to group by; without it the result is one row | |
| aggregates | Yes | What to compute for each group | |
| entity_set | Yes | Entity set name (plural, e.g. 'accounts', 'contacts') |