title: MDX MEDIAN() Function Incorrect Results
body: <p>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:</p>
  
  <pre><code>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].&amp;[476]);
  </code></pre>
  
  <p>The output is:</p>
  
  <p><a href="https://i.stack.imgur.com/3G0cM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3G0cM.png" alt="Median output"></a></p>
  
  <p>My <code>[Measures].[avgOrderSize]</code> is correct as it appears to be using the actual measures returned in the query. However, the <code>[Measures].[Median Qty]</code> 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?</p>
  
  <p>I have tried variations on <code>[Product].[Product Categories].siblings</code> including <code>[Product].[Product Name].CurrentMember</code> 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?</p>