title: Nested CALCULATE() expressions to sum for related projects where criteria met
body: <p>Following on from <a href="https://stackoverflow.com/questions/32958177/powerpivot-hierarchy-detection-active-projects/32958788?noredirect=1#comment53747587_32958788">this question</a> I'm looking to calculate ratios of expenses/payments for matter groups in a denormalised hierarchy. The time aspect is tricky, I want to see fact summaries for all time, but only for matters where the last matter closed in the current Financial Year (ending 30 June). Each project has indicators of whether it is the last closed in its parent matter group, and a closure date.</p>
  
  <p>A first step in this would be to calculate the total received across all matters which have a matter closed in the current financial YTD. This psuedocode would be something like:</p>
  
  <ul>
  <li>Filter to only show matters which were closed in current FY &amp;&amp; were the last closed in their group</li>
  <li>Remove filters, and sum fact table (payments in this example) for all matters with the same [UniqueParentName]</li>
  <li>Add all those sums together.</li>
  </ul>
  
  <p>This sounded like a prime opportunity for SUMX(), but the layering of CALCULATE() and the filter management is getting me turned around. I've used trial code as follows:</p>
  
  <pre><code>Recovered on closed this FY :=CALCULATE (
  CALCULATE (
      [Recovery All Time],
      ALLEXCEPT (
          MatterListView,
          MatterListView[UniqueParentName]
      )
  ),
  MatterListView[LastClosed] = TRUE (),
  USERELATIONSHIP ( MatterListView[ClosureDate], Date_Table[dateDate] ),
  DATESYTD ( Date_Table[dateDate], "30 June" ))
  </code></pre>
  
  <p>This relying on [Recovery All Time], which is currently a simple:</p>
  
  <pre><code>=CALCULATE (
  SUM ( MatterPayment[Payment Amount] ),
  ALL ( Date_Table[DateDate] ))
  </code></pre>