title: Get the total count per department
body: <p>This question is a link to <a href="https://stackoverflow.com/questions/24387610/getting-count-of-all-repeated-rows-in-a-datatable-in-c-sharp">Count Duplicates</a></p>
  
  <p>I have a output like this:</p>
  
  <pre><code>Department    Name     Count
  Sales         John     2
  Sales         Peter    1
  Admin         Jack     1
  Admin         Sophia   2
  Admin         Jill     1
  Maintenance   Bob      2
  Maintenance   Henry    1
  </code></pre>
  
  <p>What I want to output using this info is:</p>
  
  <pre><code>Department    Name     Count
  Sales         John     2
  Sales         Peter    1
  ------------------------
  Total                  3
  ------------------------
  Admin         Jack     1
  Admin         Sophia   2
  Admin         Jill     1
  ------------------------
  Total                  4
  ------------------------
  Maintenance   Bob      2
  Maintenance   Henry    1
  ------------------------
  Total                  3
  ------------------------
  </code></pre>
  
  <p>I'm using the following code to output the first list:</p>
  
  <pre><code>var query = data.AsEnumerable()
                  .GroupBy(r =&gt; new { Dept = r.Field&lt;string&gt;("Department"),
                      Name = r.Field&lt;string&gt;("FirstName"),
                      Surname = r.Field&lt;string&gt;("LastName")})
                  .Select(grp =&gt; new
                  {
                      Dept = grp.Key.Dept,
                      Name = grp.Key.Name,
                      Surname = grp.Key.Surname,
                      Count = grp.Count()
                  });
  
              foreach(var item in query)
              {
                  newData.Rows.Add(item.Dept, item.Name, item.Surname, item.Count);
              }
  </code></pre>
  
  <p>How do I add the total count for every department?</p>