<!-- https://learnsql.cpetoday.com/functions/dax/maxx -->
# MAXX

Language: DAX
Category: Aggregation
Syntax: MAXX(<table>, <expression>)
Summary: Evaluates an expression on each row of a table and returns the largest result.
Returns: A value (a scalar). BLANK when there are no values in the table.
Level: Intermediate
Related: MAX, MINX, AVERAGEX, SUMX, CALCULATE, VALUES

## What it does
MAXX is MAX for calculations. It walks a table, calculates the expression on each row, and returns the largest result. It answers questions such as "which customer has the largest balance" or "which store has the highest sales per square metre," where the value to compare is worked out, not stored.

## Syntax and arguments
- table: the rows to check, such as `VALUES(Customer[CustomerName])` or `ALL(Sales)`. A table function is needed here, not a single column.
- expression: the value to compare for each row, which may be a measure.

## Example
The sales VP wants the single best product by gross margin amount in the selected period.

```dax
Best Product Margin =
MAXX(
    VALUES(Product[ProductName]),
    [Gross Margin]
)
```

Each product's gross margin is calculated in its own context, and the largest value is returned. A companion measure that returns the name of the product with the highest value is the usual next step in a dashboard.

## Example: a second, different use
The largest single sales line in the period, for a large transaction review:

```dax
Largest Line =
MAXX(
    Sales,
    Sales[SalesAmount]
)
```

This gives the same answer as MAX(Sales[SalesAmount]). It becomes useful when the expression is a calculation, such as quantity times price on each line.

## Things to watch
- MAXX compares rows, so the table decides the answer. Summarizing with VALUES or SUMMARIZE first keeps the comparison at the right level, such as customer or product.
- Blank results are skipped.
- Measures in the expression are evaluated per row. Keep the row list small for speed.
- MAX works on a single column. MAXX is for a calculation or a table.
- A maximum of a ratio, such as the highest margin percentage, is not the margin percentage of the total. Read it as "the best single item."

## In business terms
MAXX finds the top customer, product, branch or project by any calculated measure. Finance teams use it for the biggest exposure in a credit file, the highest cost center overrun and the best performing channel.
