I am trying to implement a data cube whereby I can show the average and the median of a measure for a given set of dimensions. Basic example using AdventureWorksDW:
WITH
MEMBER [Measures].[Median Qty] AS
MEDIAN ( [Product].[Product Categories].siblings, [Measures].[Reseller Sales-Order Quantity])
MEMBER [Measures].[avgOrderSize] AS
CASE
WHEN [Measures].[Reseller Sales Count] = 0 THEN NULL
ELSE ([Measures].[Reseller Sales-Order Quantity] / [Measures].[Reseller Sales Count])
END
SELECT {[Measures].[Reseller Sales-Order Quantity], [Measures].[Median Qty], [Measures].[avgOrderSize]} ON 0,
NON EMPTY([Product].[Product Categories].[Category]) ON 1
FROM [Analysis Services Tutorial]
WHERE ([Product].[Product Name].&[476]);
The output is:
My [Measures].[avgOrderSize]
is correct as it appears to be using the actual measures returned in the query. However, the [Measures].[Median Qty]
is not at all correct for what my requirements are. I would have though the value would be around 6 (given that my AdventureWorksDW2012 has 344 reseller orders that include this product). It looks like the MEDIAN() is working across the entire set of products?
I have tried variations on [Product].[Product Categories].siblings
including [Product].[Product Name].CurrentMember
which returned the identical value as the Reseller Sales-Order Quantity
What am I doing wrong and how can I get the MEDIAN() function to act like I am expecting?