title: Doing a LINQ join, then group by, then a sum on two different columns
body: <p>I am using LINQ to SQL in a project and I am having an issue doing both a <code>join</code> and a <code>group by</code> to do a comparison between the two fields that are in each table.</p>
  
  <p>Here is what my query looks like:</p>
  
  <pre><code>var q =
     (from ii in
          (from a in table1
           join b in table2 on a.BudgetUnitID equals b.BudgetUnitID
           select new { BT = a.Amount, BA = b.Amount, BUID = a.BudgetUnitID, BU = a.BudgetUnit.BudgetUnitName })
      group ii by new {ii.BUID} into g
      select new
      {
          BudgetUnit = g.Key,
          Budget = g.Sum(x =&gt; x.BA),
          Actual = g.Sum(x =&gt; x.BT),
          Variance = g.Sum(x =&gt; x.BA) - g.Sum(x =&gt; x.BT)
      }).ToList();
  </code></pre>
  
  <p>I am am going to bind this to a grid view on a web page. My problem is that I am not getting the totals correct on one of the columns.</p>
  
  <p>Your help is much appreciated.</p>