Median sales per customer with MEDIANX
Find the typical customer’s spend with MEDIANX, a number that big spenders can’t drag up the way they drag up an average.
You will learn to
- Iterate customers with an X function and a measure
- Explain the difference between the median and the average
- Know that MEDIANX skips customers with no sales
How it works
The **average** spend per customer is easy to skew: one huge account lifts it for everyone. The **median** is the middle customer when you line them all up by spend, so half spent more and half spent less. When the two disagree, a few big (or small) customers are pulling the average.
`MEDIANX(table, expression)` works like `AVERAGEX`: it evaluates the expression for each row of the table, then returns the middle value. To get one value per customer, iterate the customers that are visible, `VALUES(Customer[Customer])`, and use the measure `[Total Sales]` so context transition filters each customer’s own sales.
Customers with no sales in the period get a blank, and MEDIANX skips blanks, just as AVERAGEX does. The middle customer is always a customer who bought.
Practice it hands-on with a real data model and a live report that updates as you type.
Median Units per Product = MEDIANX(VALUES(Product[Product]), [Total Quantity])