**MAX(***recordset, value ***[, KEYED ] ****[, UNORDERED |
ORDERED(** *bool ***) ] [,
STABLE | UNSTABLE ] [, PARALLEL [ (** *numthreads
***) ] ] [, ALGORITHM(**
*name ***) ] )**

**MAX(***valuelist***)**

recordset | The set of records to process. This may be the name of a dataset or a record set derived from some filter condition, or any expression that results in a derived record set. This also may be the keyword GROUP to indicate finding the maximum value of the field in a group, when used in a RECORD structure to generate crosstab statistics. |

value | The expression to find the maximum value of. |

KEYED | Optional. Specifies the activity is part of an index read operation, which allows the optimizer to generate optimal code for the operation. |

valuelist | A comma-delimited list of expressions to find the maximum value of. This may also be a SET of values. |

UNORDERED | Optional. Specifies the output record order is not significant. |

ORDERED | Specifies the significance of the output record order. |

bool | When False, specifies the output record order is not significant. When True, specifies the default output record order. |

STABLE | Optional. Specifies the input record order is significant. |

UNSTABLE | Optional. Specifies the input record order is not significant. |

PARALLEL | Optional. Try to evaluate this activity in parallel. |

numthreads | Optional. Try to evaluate this activity using
numthreads threads. |

ALGORITHM | Optional. Override the algorithm used for this activity. |

name | The algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options. |

Return: | MAX returns a single value. |

The **MAX **function either returns the
maximum *value* from the specified *recordset
*or the *valuelist*. It is defined to return
zero if the *recordset* is empty.

Example:

```
MaxVal2 := MAX(4,8,16,2,1);
SetVals := [4,8,16,2,1];
MaxVal3 := MAX(SetVals);
OUTPUT(MaxVal2); //returns 16
OUTPUT(MaxVal3); //returns 16
//example using a DATASET
SalesRecord := RECORD
INTEGER OrderNumber;
INTEGER SaleAmount;
END;
Sales := DATASET([{923,1001},
{924,23},
{925,3000},
{926,3423},
{927,9999},
{931,113}], SalesRecord);
OUTPUT(MAX(Sales,Sales.SaleAmount)); //returns 9999
```