title: LINQ - group by, then sum conditionally
body: <p>I have a data set (cars):  </p>
  
  <pre><code>Brand     DateSold    Amount  Bought/Sold
  Toyota    06/07/2015  18.5    Bought
  BMW       01/01/2016  25.15   Sold
  Mercedes  06/06/2016  20.75   Bought  
  </code></pre>
  
  <p>and I want to group by year and return the sum of the amounts i.e.:</p>
  
  <pre><code>Year Amount  
  2015 -18.5   
  2016 4.4
  </code></pre>
  
  <p>and output it into a listbox. </p>
  
  <p>I can sum without the bought/sold condition:</p>
  
  <pre><code>var AmountsByYear = cars.GroupBy(i =&gt; i.Date.Year)
                          .Select(g =&gt; new { 
                              Year = g.Key,
                              Total = g.Sum(i =&gt; i.Amount)
                          }).ToList();
  lstAmountsByYear.DataSource = AmountsByYear;
  </code></pre>