Reputation: 153
I wanted to calculate the median of the total sales for each category.
If I create the following two measures, it works perfectly:
SoS := SUM(Table1[Sales])
Median Category Sales :=
MEDIANX(
CALCULATETABLE(VALUES(Table1[Category]), ALL(Table1)),
[SoS]
)
However, If I don't nest the measures the median is not calculated and it returns just the sum.
Median without measure :=
MEDIANX(
CALCULATETABLE(VALUES(Table1[Category]), ALL(Table1)),
SUM(Table1[Sales])
)
See results below:
Why this happens? I thought the two approaches were exactly the same.
Upvotes: 0
Views: 302
Reputation: 129
Actually, the first approach is equivalent to the following:
Median Category Sales :=
MEDIANX(
CALCULATETABLE(VALUES(Table1[Category]), ALL(Table1)),
CALCULATE(SUM(Table1[Sales]))
)
The SoS measure implicitly wraps its formula in a CALCULATE which causes a context transition for each Category provided through VALUES, thereby correctly calculating the sume of sales and therefore the median.
Upvotes: 1