title: MDX: Get parent of leaves of ragged hierarchy
body: <p>I working on report to display each country and how many reps and sales managers in this country for the measure of reps count I created by found the lowest level and by this query. </p>
  
  <pre><code>iif(IsLeaf([FF Hierarchy].[FF Hierarchy].currentmember),[Measures].[#Employees],null)
  </code></pre>
  
  <p>The problem is Sales manager isn't known level we can know this member is Sales manager when he is parent of rep in other meaning parent of the leaf 
  I don't know how get this level. </p>
  
  <p>This is my code:</p>
  
  <pre><code>   with member [#Reps1] as
       iif(IsLeaf([FF Hierarchy].[FF Hierarchy].currentmember),[Measures].[#Employees],null)
       member [# of rep1] as
       SUM(DESCENDANTS([FF Hierarchy].[FF Hierarchy].currentmember,0,SELF_AND_AFTER),[Measures].[#Reps1])
  
       SELECT NON EMPTY { [Measures].[# of rep1] } ON COLUMNS,
       NON EMPTY { 
       ([FF Hierarchy].[Business Unit].[Business Unit].MEMBERS  )
       * Descendants([FF Hierarchy].[FF Hierarchy],1,self) 
       } ON ROWS 
       FROM [FFE Cube] 
  </code></pre>