title: How to get the ID of the max value while using Summarize
body: <p>I'm trying to create a calculated field in Excel's PowerPivot and am having trouble getting the results I want. Specifically, I'm trying to get the name of the item with the highest value from a subsequent column in the results of a summarize or groupby clause. </p>
  
  <p><strong>Sample Data:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/MjWyj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MjWyj.png" alt="Sample Data:"></a></p>
  
  <p>The calculation is a two step process:</p>
  
  <ol>
  <li>Sum the # of Hours by Project</li>
  <li>Return the Name/ID of the project with the highest sum</li>
  </ol>
  
  <p>In this example, the final result should be "D", as "D"s Sum of Hours is the highest (10).</p>
  
  <p>I'm able to determine the highest number of hours using this calculated field:</p>
  
  <p><code>Test:=MAXX(Summarize(ExampleTable, [Project], "TotalHours", Sum([Hours])), [TotalHours])</code></p>
  
  <p>I'm not sure how to either adjust this calculated field or create a new calculated field to return "D".</p>
  
  <p>Further complicating things, the results must take the current filter context into example, so that the results are always correct no matter what the user does. Here's a more robust set of sample data and expected results:</p>
  
  <p><a href="https://i.stack.imgur.com/4LPfm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4LPfm.png" alt="Complicated Example"></a></p>
  
  <p>Here are the expected results in terms of hours. For each yellow cell, I want the result of the calculated field to be the name of the project (A-E).</p>
  
  <p><a href="https://i.stack.imgur.com/YpEw1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YpEw1.png" alt="Expected results"></a></p>
  
  <p>Here's an example of an actual report showing the MaxHours instead of the project name. My goal is to show Project Name instead of MaxHours. (Feel free to ignore the subtotals).</p>
  
  <p><a href="https://i.stack.imgur.com/Z3oH8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z3oH8.png" alt="Sample Report"></a></p>
  
  <p><code>MaxHours:=MAXX(SUMMARIZE(Table1,[Project],"Total Hours",sum([Hours])),[Total Hours])</code></p>
  
  <p>Here's the example results without subtotals:</p>
  
  <p><a href="https://i.stack.imgur.com/QSWAW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QSWAW.png" alt="Sample results"></a></p>
  
  <p>NOTE: We can assume no ties for the purpose of this question.</p>