# Max - script function

Max() finds the highest numeric value of the aggregated data in the expression, as defined by a group by clause. By specifying a rank n, the nth highest value can be found.

Syntax:

Max (Max ( expr [, rank]expr [, rank]))

Return data type: numeric

Arguments:

Max arguments

| Argument | Description |
| --- | --- |
| expr | The expression or field containing the data to be measured. |
| rank Expression | The default value of rank is 1, which corresponds to the highest value.<br>By specifying rank as 2, the second highest value is returned. If rank is 3, the third highest value is returned, and so on. |

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 our document to see the result.

Example 1:

`Temp:` `LOAD * inline [` `Customer|Product|OrderNumber|UnitSales|CustomerID` `Astrida|AA|1|10|1` `Astrida|AA|7|18|1` `Astrida|BB|4|9|1` `Astrida|CC|6|2|1` `Betacab|AA|5|4|2` `Betacab|BB|2|5|2` `Betacab|DD` `Canutility|DD|3|8` `Canutility|CC` `] (delimiter is '|');` ` ` `Max:` `LOAD Customer, Max(UnitSales) as MyMax  Resident Temp Group By Customer;`

Example 1 results

| Result field (Customer) | Result value (MyMax) |
| --- | --- |
| Astrida | 18 |
| Betacab | 5 |
| Canutility | 8 |

Example 2:

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

`LOAD Customer, Max(UnitSales,2) as MyMaxRank2  Resident Temp Group By Customer;`

Example 2 results

| Result field (Customer) | Result value (MyMaxRank2) |
| --- | --- |
| Astrida | 10 |
| Betacab | 4 |
| Canutility | - |