Skip to main content

Avg - script function

Avg() finds the average value of the aggregated data in the expression over a number of records as defined by a group by clause.


Avg([DISTINCT] expr)

Return data type: numeric


Argument Description
expr The expression or field containing the data to be measured.
DISTINCT If the word distinct occurs before the expression, all duplicates will be disregarded.

Examples and results:  

Add the example script to your app and run it. To see the result, add the fields listed in the results column to a sheet in your app.

Resulting data
Example Result


crosstable (Month, Sales) load * inline [






] (delimiter is '|');



LOAD Customer, Avg(Sales) as MyAverageSalesByCustomer Resident Temp Group By Customer;


Customer MyAverageSalesByCustomer

Astrida 48.916667

Betacab 44.916667

Canutility 56.916667

Divadip 63.083333

This can be checked in the sheet by creating a table including the measure:

Given that the Temp table is loaded as in the previous example:

LOAD Customer,Avg(DISTINCT Sales) as MyAvgSalesDistinct Resident Temp Group By Customer;

Customer MyAverageSalesByCustomer

Astrida 43.1

Betacab 43.909091

Canutility 55.909091

Divadip 61

Only the distinct values are counted. Divide the total by the number of non-duplicate values.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!