title: Excel pivot table: move value fields from row to column
body: <p>I'm developing an excel addin in c# and have to create a pivot table, which I don't know how to organize the data, how it should be.</p>
  
  <p>First of all the datasource:</p>
  
  <p><img src="https://i.stack.imgur.com/D8Gc0.jpg" alt="Pivot Data Source"></p>
  
  <p>This is, how the final Pivot Table should looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/NWXfM.jpg" alt="Pivot should looks like this"></p>
  
  <p>But I only get something like this and I have no Idea where I have to how to change my code:</p>
  
  <p><img src="https://i.stack.imgur.com/W8LA4.jpg" alt="This is what my code does with it -.-"></p>
  
  <p>Finally my code to arrange the data source columns:</p>
  
  <pre><code>/* PIVOT RowFields */
  Excel.PivotField nameField = pTable.PivotFields("Name");
  nameField.Orientation = Excel.XlPivotFieldOrientation.xlRowField;
  nameField.Position = 1;
  
  Excel.PivotField monthField = pTable.PivotFields("Monat");
  monthField.Orientation = Excel.XlPivotFieldOrientation.xlRowField;
  monthField.Position = 2;
  
  /* PIVOT Data */
  Excel.PivotField sum200Field = pTable.PivotFields("Summe 1");
  sum200Field.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
  
  Excel.PivotField sum700Field = pTable.PivotFields("Summe 2");
  sum700Field.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
  
  Excel.PivotField sumDiffField = pTable.PivotFields("Differenz");
  sumDiffField.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
  </code></pre>
  
  <p>I'm using .NET Framework 4 ... I read a lot of articles in the internet, but nothing I read was useful... </p>
  
  <p>Does anyone have an Idea?</p>
  
  <p>UPDATE:</p>
  
  <p>As @MP24 posted, adding these two C#-Lines at the end of my code, the columns will be display right exclusive the grouping of name and month:</p>
  
  <pre><code>Excel.PivotField dataField = pTable.DataPivotField;
  dataField.Orientation = Excel.XlPivotFieldOrientation.xlColumnField;
  </code></pre>
  
  <p>UPDATE2:</p>
  
  <p>To group Month and Name Column, the following code will show how to:</p>
  
  <pre><code>/* PIVOT ZEILEN */
  Excel.PivotField monthField = pTable.PivotFields("Monat");
  monthField.Orientation = Excel.XlPivotFieldOrientation.xlRowField;
  monthField.LayoutCompactRow = true;
  monthField.LayoutForm = Excel.XlLayoutFormType.xlOutline;
  monthField.set_Subtotals(1, false);
  
  Excel.PivotField nameField = pTable.PivotFields("Name");
  nameField.Orientation = Excel.XlPivotFieldOrientation.xlRowField;
  nameField.LayoutCompactRow = true;
  nameField.set_Subtotals(2, false);
  </code></pre>