Forum Discussion
Unorthodox Median Calculation
- 8 years ago
Hi again,
It turns out you can do something like this, assuming you have enabled all functions in DirectQuery.
I have taken this code basically verbatim from
https://www.daxpatterns.com/statistical-patterns/#median22
Median Unorthodox = VAR NumValuesHalved = COUNT ( YourTable[Latency] ) / 2 RETURN MINX ( FILTER ( VALUES ( YourTable[Latency] ), CALCULATE ( COUNT ( YourTable[Latency] ), YourTable[Latency] <= EARLIER ( YourTable[Latency] ) ) > NumValuesHalved ), YourTable[Latency] )The code produces the "upper" median value in the case of an even number of items, otherwise produces the middle value.
Regards,
Owen :)
Hi again,
It turns out you can do something like this, assuming you have enabled all functions in DirectQuery.
I have taken this code basically verbatim from
https://www.daxpatterns.com/statistical-patterns/#median22
Median Unorthodox =
VAR NumValuesHalved = COUNT ( YourTable[Latency] ) / 2
RETURN
MINX (
FILTER (
VALUES ( YourTable[Latency] ),
CALCULATE (
COUNT ( YourTable[Latency] ),
YourTable[Latency] <= EARLIER ( YourTable[Latency] )
)
> NumValuesHalved
),
YourTable[Latency]
)The code produces the "upper" median value in the case of an even number of items, otherwise produces the middle value.
Regards,
Owen :)
- Artemis12548 years agoFrequent Visitor
Thanks so much for your help. I can't even begin to tell you how much time I spent trying to google the answer and find out. Cheers