title: C# linq pivot or crosstab or transpose?
body: <p>First post ever so please forgive if I am out of line.</p>
  
  <pre><code>StreamWriter noteswriter = new StreamWriter(directoryPath + "\\" + "Notes.CSV");
  
  var NotesQuery =
      from w in
          (from line in BillSummaryQuery1
           let linerecord2 = line.Split(',').ToList()
           where linerecord2[0] == "RB" &amp;&amp; linerecord2[1] == "MICA" &amp;&amp; linerecord2[6].Trim() == "1" &amp;&amp; linerecord2[7].Trim() == "H" &amp;&amp; linerecord2[9].Trim() == "D" &amp;&amp; Regex.IsMatch(linerecord2[10].Substring(4, 1), @"^[a-zA-Z0-9]*$") &amp;&amp; linerecord2[10].Substring(2, 1) == " "
           select string.Concat(linerecord2[2], ",", linerecord2[3], ",", linerecord2[10].Trim())
           )
      let lineorder3 = w.Split(',').ToList()
      select new
      {
          colA = lineorder3[0],
          colB = lineorder3[1],
          colC = lineorder3[2]
      };
  
  var NotesQuery1 =
  from w in NotesQuery
      group w by new { w.colA, w.colB, w.colC } into g
      select new
      {
          colA = g.Key.colA, 
          colB = g.Key.colB, 
          colC = g.Key.colC
      };
  
  foreach (var item in NotesQuery1)
  {
      noteswriter.WriteLine(item);
      toolStripProgressBar1.ProgressBar.PerformStep();
  }
  
  noteswriter.Dispose();
  noteswriter.Close();
  </code></pre>
  
  <p>This gives me an output such as:</p>
  
  <pre><code>{colA = AccountA,colB = Number1,colC = AccountA }
  
  {colA = AccountA,colB = Number1,colC = AccountHolderA }
  
  {colA = AccountA,colB = Number1,colC = Address1 }
  
  {colA = AccountA,colB = Number1,colC = Address2 }
  
  {colA = AccountB,colB = Number2,colC = AccountA }
  
  {colA = AccountB,colB = Number2,colC = AccountHolderB }
  
  {colA = AccountB,colB = Number2,colC = Address1 }
  </code></pre>
  
  <p>I don't know how to get the CSV file to be written as:</p>
  
  <pre><code>AccountA,Number1,AccountA,AccountHolderA,Address1,Address2
  
  AccountB,Number2,AccountA,AccountHolderB,Address
  </code></pre>
  
  <p>Any suggestion will be greatly appreciated. Thanks!</p>