title: Calculating Quartiles in Analysis Services
body: <p>I´m using <code>MDX</code> code to calculate quartile, , like in this blog:
  <a href="https://electrovoid.wordpress.com/2011/06/24/ssas-quartile/" rel="nofollow">https://electrovoid.wordpress.com/2011/06/24/ssas-quartile/</a></p>
  
  <p>That is what I´m doing:</p>
  
  <pre><code>WITH SET OrderedData AS 
  ORDER
      (    
          NONEMPTY
                  (
                   [Dim Parameter].[id].[id]
                   *[Dim Result].[Id].[Id].ALLMEMBERS,
                   [Measures].[Value]
                  ),  
          [Measures].[Value], 
          BASC
       )
  
  MEMBER [Measures].[RowCount] AS COUNT (OrderedData)
  MEMBER [Measures].[i25] AS ( .25 *  ( [RowCount] - 1 ) ) + 1
  MEMBER [Measures].[i25Lo] AS FIX([i25])   - 1
  MEMBER [Measures].[i25Rem] AS ([i25] - FIX([i25]))
  MEMBER [Measures].[n25Lo] AS (OrderedData.Item([i25Lo]), [Value])
  MEMBER [Measures].[n25Hi] AS (OrderedData.Item([i25Lo] + 1), [Value])
  MEMBER [Measures].[Quartile1] AS [n25Lo] + ( [i25Rem] * ( [n25Hi] - [n25Lo] ))
  ,FORMAT_STRING='Currency'
  MEMBER [Measures].[Quartile2] AS MEDIAN(OrderedData, [Value])
  ,FORMAT_STRING='Currency'
  MEMBER [Measures].[i75] AS ( .75 *  ( [RowCount] - 1 ) ) + 1
  MEMBER [Measures].[i75Lo] AS FIX([i75]) - 1
  MEMBER [Measures].[i75Rem] AS ([i75] - FIX([i75]))
  MEMBER [Measures].[n75Lo] AS (OrderedData.Item([i75Lo] ),[Value])
  MEMBER [Measures].[n75Hi] AS (OrderedData.Item([i75Lo] + 1),[Value])
  MEMBER [Measures].[Quartile3] AS [n75Lo] + ( [i75Rem] * ( [n75Hi] - [n75Lo] ))
  ,FORMAT_STRING='Currency'
  MEMBER [Measures].[RIC] As ([Quartile3]-[Quartile1] )
  MEMBER [Measures].[Ls] As ([Quartile3]+ ([RIC]*1.5) )
  MEMBER [Measures].[Li] As ([Quartile1]- ([RIC] *1.5)) 
  MEMBER [Measures].[MAX] as  MAX (Filter(OrderedData ,[value]&lt;=[LS]),[value])
  MEMBER [Measures].[Min] as  MIn(Filter(OrderedData ,[value]&gt;=[Li]),[value])
  MEMBER [Measures].[out] as  MAX (Filter(OrderedData ,[value]&gt;[LS]),[value
  </code></pre>
  
  <p>What I want is to add Dim date, to calculate the quartiles for each month, something like this:</p>
  
  <pre><code>MEMBER [Measures].[out] as MAX (Filter(OrderedData ,[value]&gt;[LS]),[value
  
  SELECT {
          [Measures].[Quartile1],[Measures].[Quartile2],[Measures].[Quartile3], [min],
  
          [MAX] , [out] , [Measures].[ValueAVG],[RowCount],[Measures].[Recuento Fact Result]
         } ON 0 , 
  [Dim Parameter].[Reference].[Reference] * 
  [Dim Parameter].[Section ES].[Section ES] * 
  [Id Distribution Date].[DateJ].[Month] ON 1 
  FROM [Tess Tek DW Dev]
  </code></pre>
  
  <p>But it didn't work, How i can calculate quartiles of different date ranges in only one <code>mdx</code> query?</p>