Dynamics AX 2012 - Avg function

Hello, I would like to know how to use the avg function in a select statement.

Thanks for the answers!! :slight_smile:

Hi there,

it is fairly similar to Transact SQL, you use the following structure:

select avg(FieldName) from table;

Then to see the results you just refer to the field you used the expression avg using table.Fieldname

This is valid for the other common expressions such as count, minOf , maxOf and since it is destined to numbers, don´t try placing str columns or the code will fail.

Thanks for the answer!!

In the MOC there isn’t an example of this function…

One thing to keep in mind. The results of aggregate calculations (such as AVG) are returned in the field on which the calculation is performed, so the result has the same data type as the field itself. Therefore, if you perform AVG on an int field, the result will be truncated to an int.