title: Convert Datatable GroupBy Multiple Columns with Sum using Linq
body: <p>I want to sum of all TotalImages Column after Group BY but its' showing me error.
  any one who can help me what's going wrong.
  Remember just want to use from this syntax base and want DataTable  not a List. Kindly if some one help me out will be grateful.</p>
  
  <p>Sample Data:-</p>
  
  <pre><code>CountryId | CItyId | TotalImages
  1              1        2
  1              2        2
  1              2        3
  1              3        4 
  2              1        2
  2              2        2
  2              2        3
  2              3        4 
  
  
  
  
  DataTable dt = dt.AsEnumerable()
   .GroupBy(r =&gt; new { Col1 = r["CountryId"], Col2 = r["CityId"]})
   .Select(g =&gt; g.Sum(r =&gt; r["TotalImages"]).First())
   .CopyToDataTable();
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/nWjkD.png" alt="enter image description here"></p>