<!-- https://learnsql.cpetoday.com/functions/dax/median -->
# MEDIAN

Language: DAX
Category: Aggregation
Syntax: MEDIAN(<column>)
Summary: Returns the middle value of the numbers in a column.
Returns: A number (a scalar). BLANK when the column has no numbers in the current filter context.
Level: Intermediate
Related: AVERAGE, MIN, MAX, PRODUCT, DIVIDE, COUNTROWS

## What it does
MEDIAN returns the value in the middle of a column once the numbers are sorted. Half the values are above it and half below. Unlike AVERAGE, one very large value does not pull it up. Use it when the data has big outliers, such as invoice sizes where a few large contracts would distort the mean.

## Syntax and arguments
- column: a column reference such as `Sales[SalesAmount]`. Only one column is accepted.

## Example
The collections manager wants the typical invoice size, because a handful of very large contracts make the average look much bigger than most customers see.

```dax
Median Invoice Value = MEDIAN(Sales[SalesAmount])
```

Compare this with AVERAGE(Sales[SalesAmount]) on the same card. A large gap between the two tells the reader the data is skewed, and that the median is the better guide to a normal transaction.

## Example: a second, different use
A median of days to pay, as a measure of normal payment behavior for a client group:

```dax
Median Days to Pay = MEDIAN(Invoices[DaysToPay])
```

This assumes a column that holds the number of days from invoice to payment, calculated in the source or in a calculated column. The median is not shifted by one client that always pays late.

## Things to watch
- MEDIAN is not additive. The median of a group is not the sum of the medians of its parts, and the total in a matrix is the median of all rows, not an average of the rows above it.
- Blank values are not part of the middle. Check the column for blanks before you rely on the result.
- MEDIAN takes a column. For a median of a calculation on each row, you need a table-based approach that is more advanced.
- A median of a small group can be a value that looks odd. Show the count next to it.
- The median is slower than AVERAGE on very large tables, because the values must be sorted.

## In business terms
Median is the right statistic for skewed money data: invoice size, customer balance, payment delay and claim cost. Finance teams use it to describe what a normal case looks like, and it reduces the risk that one large account drives a conclusion about all of them.
