<!-- https://learnsql.cpetoday.com/functions/dax/minx -->
# MINX

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

## What it does
MINX visits each row of a table, works out an expression for that row, and reports the smallest of those results. It is MIN for calculations. Use it when the value you want to compare is not stored in one column, such as a margin percentage for each product or a balance for each customer.

## Syntax and arguments
- table: the rows to check, such as `VALUES(Product[ProductName])` or a filtered fact table.
- expression: the value to compare for each row. It can be a measure, and each measure is evaluated for that row.

## Example
The category manager wants to know which product has the lowest gross margin percentage in the current view.

```dax
Lowest Product Margin % =
MINX(
    VALUES(Product[ProductName]),
    [Gross Margin %]
)
```

VALUES gives one row per product in context. For each product, the margin percentage is calculated for that product alone, and MINX returns the lowest one. Pair it with a card that shows the name of the product, found with a separate measure, to name the weakest product.

## Example: a second, different use
The lowest margin on any single sales line, to find pricing errors:

```dax
Thinnest Line Margin =
MINX(
    Sales,
    Sales[SalesAmount] - Sales[TotalCost]
)
```

Each line is compared on its own margin, so one bad price on one line shows up even if the total margin looks healthy.

## Things to watch
- MINX checks rows you have chosen. If the table includes lines you do not want, filter the table first.
- Blank results are skipped, so a product without sales does not appear as zero.
- Measures used inside MINX are evaluated for each row. Large tables can be slow.
- A minimum of percentages is not a weighted figure. Say so when you show it to a reader.
- MIN is used for a single column; MINX is used when a calculation on each row is needed first.

## In business terms
MINX shows the weakest item in a group: the lowest margin product, the smallest balance in a receivables list, or the lowest utilization in a team of consultants. Used with a name lookup, it tells the reader where to look first.
