General X++ Development

How do I use `sum`, `count`, `avg`, `min`, and `max` in X++?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I use sum, count, avg, min, and max in X++?

SSunny Vasty75 reputation · answered Aug 13, 2026

X++ supports aggregate functions directly in a select statement.

Example using sum:

X++
SalesLine salesLine;

select sum(LineAmount) from salesLine
    where salesLine.SalesId == 'SO-000001';

info(strFmt('Total: %1', salesLine.LineAmount));

The supported aggregate keywords include sum, count, avg, minof, and maxof.

One thing that trips people up: the result comes back through the field you aggregated. In the example above, the total is in salesLine.LineAmount.