# GrapeCity.Documents.Excel.IPivotTable.AddDataField

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="GrapeCity_Documents_Excel_IPivotTable_AddDataField_" data-uid="GrapeCity.Documents.Excel.IPivotTable.AddDataField*">AddDataField Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="GrapeCity_Documents_Excel_IPivotTable_AddDataField_" data-uid="GrapeCity.Documents.Excel.IPivotTable.AddDataField*"></a>
<h4 id="GrapeCity_Documents_Excel_IPivotTable_AddDataField_GrapeCity_Documents_Excel_IPivotField_System_String_GrapeCity_Documents_Excel_ConsolidationFunction_" data-uid="GrapeCity.Documents.Excel.IPivotTable.AddDataField(GrapeCity.Documents.Excel.IPivotField,System.String,GrapeCity.Documents.Excel.ConsolidationFunction)">AddDataField(IPivotField, string, ConsolidationFunction)</h4>
<div class="markdown level1 summary"><p>Adds a data field to the PivotTable report.</p>
<p>
Use this method to add a source field to the values area and specify the
summary function used for that data field.
</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">IPivotField AddDataField(IPivotField field, string caption, ConsolidationFunction function)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Function AddDataField(field As IPivotField, caption As String, [function] As ConsolidationFunction) As IPivotField</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.IPivotField.html">IPivotField</a></td>
      <td><span class="parametername">field</span></td>
      <td><p>The unique field on the server. If the source data is OLAP, this field is a cube field; otherwise, it is a PivotTable field.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">caption</span></td>
      <td><p>The label used in the PivotTable report to identify the added data field.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.ConsolidationFunction.html">ConsolidationFunction</a></td>
      <td><span class="parametername">function</span></td>
      <td><p>The function performed in the added data field.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.IPivotField.html">IPivotField</a></td>
      <td><p>The <a class="xref" href="GrapeCity.Documents.Excel.IPivotField.html">IPivotField</a> added to the data area.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="GrapeCity_Documents_Excel_IPivotTable_AddDataField_GrapeCity_Documents_Excel_IPivotField_System_String_GrapeCity_Documents_Excel_ConsolidationFunction__examples">Examples</h5>
<pre><code class="lang-csharp">object[,] sourceData = {
    {"Region", "Product", "Amount"},
    {"East", "Apple", 120},
    {"West", "Apple", 80},
    {"East", "Orange", 90}
};
worksheet.Range["A1:C4"].Value = sourceData;
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:C4"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["E1"], "SalesPivot");
pivotTable.PivotFields["Region"].Orientation = PivotFieldOrientation.RowField;
pivotTable.AddDataField(pivotTable.PivotFields["Amount"], "Sum of Amount", ConsolidationFunction.Sum);</code></pre>

</div>
