Aggregate query results for analysis
An aggregate is meaningful only at a defined grain: the level represented by each output row. In a query, the ordinary columns determine that grain, so review the complete projection before trusting a total.
Select aggregate methods
Use Method on a column to calculate Sum, Average, Min, or Max for a numeric field. Use Count to count matching rows. A count column doesn't need a source field:
column(EntryCount)
{
Method = Count;
}
The query groups results by its ordinary, nonaggregated columns. Adding an ordinary column can therefore split one aggregate row into several groups. Decide which columns define the business result before adding fields for display.
Verify totals after joins
A join can repeat a value when one row relates to multiple rows on the other side. Summing a measure after that join can multiply the value. Confirm which table owns the measure, inspect the join cardinality, and reconcile totals against the source rows.
Use OrderBy to sort the grouped result for its consumer. Ordering changes row sequence, not the grouping grain. For more information, see Aggregating data in query objects and Method property.