title: Linq multi level grouping
body: <p>I am trying to implement a multi level grouping in linq</p>
  
  <p>In sql it would be something like that.</p>
  
  <pre><code>Select VarId, variable, UT , 
         (case when resultat &gt;= 0 then sum(resultat) else 0) as Positive,
         (case when resultat &lt; 0 then sum(resultat) else 0) as Negatif
  from 
        (Select VarId, variable, UT , valeur, sum( resultat ) from IndicRow 
               group by VarId, variable, UT , valeur)
  group by VarId, variable, UT 
  </code></pre>
  
  <p>i have created that in linq but i can't find the way to group on the result of a group by</p>
  
  <pre><code>var Chartline = from IndicRow in Indic_dt.AsEnumerable()
                              //where SelTradeId.Contains(IndicRow.Field&lt;int&gt;("TradeNum"))
                              group IndicRow by new
                              {
                                  GpVariable = IndicRow.Field&lt;string&gt;("Variable"),
                                  GpUT = IndicRow.Field&lt;string&gt;("UT"),
                                  GPVarId = IndicRow.Field&lt;int&gt;("VarId"),
                                  GPValue = IndicRow.Field&lt;double&gt;("Valeur")
                              } into RdVal
                              select new
                              {
                                  VarId = RdVal.Key.GPVarId,
                                  Variable = RdVal.Key.GpVariable,
                                  UT = RdVal.Key.GpUT,
                                  Valeur = RdVal.Key.GPValue,
                                  Resultat = RdVal.Sum(IndicRow =&gt; IndicRow.Field&lt;double&gt;("Resultat_EuroNet"))
                              };
  </code></pre>
  
  <p>The final goal is to obtain a 5 columns Datatable (VarId, variable, UT, Positive, negative)</p>