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.
Return data type: numeric
|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.
crosstable (Month, Sales) load * inline [
] (delimiter is '|');
LOAD Customer, Avg(Sales) as MyAverageSalesByCustomer Resident Temp Group By Customer;
Divadip 63.083333This 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;
Divadip 61Only the distinct values are counted. Divide the total by the number of non-duplicate values.