<!-- https://learnsql.cpetoday.com/functions/dax/max -->
# MAX

Language: DAX
Category: Aggregation
Syntax: MAX(<column>) or MAX(<expression1>, <expression2>)
Summary: Returns the largest value in a column, or the larger of two values.
Returns: A value of the same type as the input (a scalar). BLANK when the column has no values in the current filter context.
Level: Beginner
Related: MAXX, MIN, SUM, LASTDATE, LASTNONBLANK, COALESCE

## What it does
MAX finds the highest value in one column that is still visible after the filters are applied. Its second form compares two values and returns the larger. Use it for the largest invoice, the latest posting date, or the peak monthly balance.

## Syntax and arguments
- column: a column reference such as `Sales[SalesAmount]`. Blank values are ignored.
- expression1, expression2 (second form): two single values. The larger one is returned, which is handy for setting a minimum.

## Example
The credit controller wants the largest single invoice in the selected period, to watch concentration risk.

```dax
Largest Invoice = MAX(Sales[SalesAmount])
```

In a matrix by customer, each customer row shows that customer's biggest invoice line. The grand total shows the biggest line across all customers.

## Example: a second, different use
The most recent transaction date, used as the "as of" date on a report:

```dax
Last Posting Date = MAX('Date'[Date])
```

If the date table is filtered to a closed period, the result is the last day of that period that has data. For the last date with sales, use the date column of the fact table instead.

## Things to watch
- MAX ignores blanks. If nothing is left in the context, the result is BLANK.
- For a calculation on each row first, use MAXX. MAX takes a column, not an expression.
- A maximum of a date column is the latest date. Be careful with a date table that has dates in the future, which can make the report look as if it ran later than it did.
- MAX with two values is for single values only. Do not confuse it with a row by row maximum.
- A maximum is not a total. Summing the maxima of several groups gives a number that has no meaning.

## In business terms
MAX is used for the largest outstanding balance, peak inventory, highest expense claim, the latest close date and the top price in a price list. Auditors and controllers use it to look for outliers and approval thresholds.
