title: How to optimize MDX that should conditionally decide between two Measures based on the half Year choosen (involving SCOPE, Descendants Statements)
body: <p>The [Conditional Forecast Cost] is generated by following SCOPE-Statements based on measures called "Cost" and "Forecast Cost".</p>
  
  <p>These Statements work fine but it is too slow. Especially if the whole YEAR is choosen in the report (or even more Years). Waiting time can be more than 5 Minutes.
  Any Idea how to optimize this MDX ?</p>
  
  <pre><code>SCOPE ([Measures].[Conditional Forecast Cost]);           
  THIS =    (IIF([DIM Date].[Half Year].&amp;[1],[Measures].[Cost], [Measures].[Forecast Cost]));
  END SCOPE;
  
  SCOPE ([DIM Date].[Iso Month].[All].children, [Measures].[Forecast Costs]);           
      THIS =     SUM(
                    Descendants(
                                 [DIM Date].[Iso Month].CurrentMember, 
                                 [DIM Date].[Iso Month]
                               ), 
                      [Measures].[Conditional Forecast Cost]
                     );   
  END SCOPE;
  </code></pre>
  
  <p><strong>Background information:</strong></p>
  
  <p>First Statement represents the basic Logic.</p>
  
  <ul>
  <li>If the first half year is choosen the Measure "Cost" should be
  applied.</li>
  <li>For the second half year the Measure "Forecast Cost" should be
  applied.</li>
  </ul>
  
  <p>That works fine as long as we are reporting on a monthly Level.</p>
  
  <ul>
  <li>If the whole year should be aggregated the first Statement is not
  enough because the engine will  not aggrate the way we have defined
  it with "IIF([DIM Date].[Half Year].&amp;[1],[Measures].[Cost] ..." .</li>
  </ul>
  
  <p>So the second SCOPE Statement with the Descendants Function forces the engine to do the aggregation from the lower monthly level.
  That works so far but it is really slow.</p>
  
  <p><strong>Additional information:</strong></p>
  
  <ul>
  <li>For now we would prefer to implement this Logic in the semnatic Layer
  with MDX and not in the ETL.</li>
  <li>The "Cost" Measure is also a calculated Measure in the MDX.</li>
  <li>The DIM Date Dimension has a hierachy just with "YEAR-Month" (of
  course some additional Attributes).</li>
  </ul>