# 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.

Syntax:

Avg([DISTINCT] expr)

Return data type: numeric

Arguments:

Avg arguments

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

Examples and results:

Add the example script to your document and run it. Then add, at least, the fields listed in the results column to a sheet in your document to see the result.

Examples and results

| Example | Result |
| --- | --- |
| `Temp:`<br>`crosstable (Month, Sales) load * inline [`<br>`Customer\|Jan\|Feb\|Mar\|\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec`<br>`Astrida\|46\|60\|70\|13\|78\|20\|45\|65\|78\|12\|78\|22`<br>`Betacab\|65\|56\|22\|79\|12\|56\|45\|24\|32\|78\|55\|15`<br>`Canutility\|77\|68\|34\|91\|24\|68\|57\|36\|44\|90\|67\|27`<br>`Divadip\|36\|44\|90\|67\|27\|57\|68\|47\|90\|80\|94`<br>`] (delimiter is '\|');`<br><br>`Avg1:`<br>`LOAD Customer, Avg(Sales) as MyAverageSalesByCustomer Resident Temp Group By Customer;<br>`<br>` ` | `Customer MyAverageSalesByCustomer`<br>`Astrida 48.916667`<br>`Betacab 44.916667`<br>`Canutility 56.916667`<br>`Divadip 63.083333`This can be checked in the sheet by creating a table including the measure:<br>`Sum(Sales)/12` |
| Given that the Temp table is loaded as in the previous example:<br><br>`LOAD  Customer,Avg(DISTINCT Sales) as MyAvgSalesDistinct Resident Temp Group By Customer;` | `Customer MyAverageSalesByCustomer`<br>`Astrida 43.1`<br>`Betacab 43.909091`<br>`Canutility 55.909091`<br>`Divadip 61`Only the distinct values are counted. |