title: Create a Pivot Table from a DataTable
body: <p>I am using C# winforms to create an application that needs to turn a datatable into a pivot table.  I have the pivot table working fine from a SQL end, but creating it from a datatable seems trickier.  I couldn't seem to find anything built into .NET for this.  </p>
  
  <p>NOTE: I do have to do this from a .NET side as I manipulate the data prior to creating the pivot.</p>
  
  <p>I've read through some articles that did some similar things as this, but I've had difficultly applying them to my problem.  </p>
  
  <p>*I have a datatable with the columns "StartDateTime", "Tap", and "Data".  The startdates should be grouped together and data values averaged (sometimes more than one data value per startdate).  The table is shown below:</p>
  
  <p><img src="https://i.stack.imgur.com/kwxzl.png" alt="enter image description here"></p>
  
  <p>Pivot table should output like the image below (not rounded values though).  The column numbers are the distinct tap numbers (one for each unique one).</p>
  
  <p><img src="https://i.stack.imgur.com/Li9Cu.png" alt="Pivot Table"></p>
  
  <p>How can I go about creating this pivot table from the datatable?  </p>
  
  <p>EDIT: forgot to mention, these tap values are not always from 1-4, they do vary in number and value.</p>