[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Collapse]Spreadsheet
    Product Structure
   [Expand]Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
   [Expand]Pivot Table Overview
   [Expand]Charts and Graphics
    Printing
    Events
    Protection
    Operation Restrictions
    Find and Replace
   [Expand]Mail Merge
   [Expand]Visual Elements
    Services
    Themes and Templates
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheet
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Data Binding
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Tables
    [Collapse]Pivot Tables
      How to: Create a Pivot Table
      How to: Refresh a Pivot Table
      How to: Change a Data Source for a Pivot Table
      How to: Move a Pivot Table
      How to: Clear or Remove a Pivot Table
      How to: Change the PivotTable Layout
      How to: Subtotal Fields in a Pivot Table
      How to: Display or Hide Grand Totals for a Pivot Table
      How to: Format Numbers and Dates in a Pivot Table
      How to: Apply a Predefined Style to a Pivot Table
      How to: Apply a Custom Style to a Pivot Table
      How to: Control Style Options
      How to: Change the Summary Function for a Data Field
      How to: Apply a Custom Calculation to a Data Field
      How to: Create a Calculated Field
      How to: Create a Calculated Item
      How to: Sort Items in a Pivot Table
      How to: Filter Items in a Pivot Table
      How to: Group Items in a Pivot Table
    [Expand]Printing
    [Expand]Pictures
    [Expand]Shapes
    [Expand]Charts
    [Expand]Sparklines
    [Expand]Protection
    [Expand]Mail Merge
    [Expand]Cell Templates
    [Expand]Commands
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Apply a Custom Calculation to a Data Field

Summaries in the data area are calculated according to the data field's PivotDataField.SummarizeValuesBy property. By default, they are displayed "as is". However, you can use the PivotDataField.ShowValuesWithCalculation method overloads to apply an additional calculation option to the raw summary values to change the way they are displayed in the PivotTable report.

The available calculation options are defined by the values of the PivotShowValuesAsType enumeration and listed in the table below. Depending on the selected option, you may need to specify either a base field or a base field and its base item that will serve as a basis for a custom calculation. Only a field from the row or column area can be used as a base field, otherwise, all results will be shown as a #N/A error.

Calculation Option

PivotShowValuesAsType Member

Description

% of Grand Total

PivotShowValuesAsType.PercentOfTotal

Displays values as the percentage of the grand total of all values in the PivotTable report.

% of Column Total

PivotShowValuesAsType.PercentOfColumn

Displays values in each column as the percentage of the total value of the column.

% of Row Total

PivotShowValuesAsType.PercentOfRow

Displays values in each row as the percentage of the total value of the row.

% of Parent Column Total

PivotShowValuesAsType.PercentOfParentColumn

Displays values in each inner column as the percentage of the total of the parent item in the outer column.

% of Parent Row Total

PivotShowValuesAsType.PercentOfParentRow

Displays values in each inner row as the percentage of the total of the parent item in the outer row.

Index

PivotShowValuesAsType.Index

Calculates the relative importance of each summary value by using the following formula:

((value in cell) x (Grand Total of Grand Totals)) / ((Grand Row Total) x (Grand Column Total))

% of Parent Total

PivotShowValuesAsType.PercentOfParent

Displays values in a data field as the percentage of the value of the parent item in the specified base field.

Rank Smallest to Largest

PivotShowValuesAsType.RankAscending

Displays the rank of values for a specific base field, listing the smallest item in the field as 1, and each larger value with a higher rank value.

Rank Largest to Smallest

PivotShowValuesAsType.RankDescending

Displays the rank of values for a specific base field, listing the largest item in the field as 1, and each smaller value with a higher rank value.

Running Total In

PivotShowValuesAsType.RunningTotal

Displays values for successive items in the base field as a running total.

% Running Total In

PivotShowValuesAsType.PercentOfRunningTotal

Calculates a running total for successive items in the base field as a percentage of the grand total value.

% Of

PivotShowValuesAsType.Percent

Displays values as the percentage of the value of the base item in the base field.

Difference From

PivotShowValuesAsType.Difference

Displays values as the difference from the value of the base item in the base field.

% Difference From

PivotShowValuesAsType.PercentDifference

Displays values as the percentage difference of the value of the base item in the base field.

To remove any custom calculation applied to a data field, pass the PivotShowValuesAsType.NoCalculation enumeration member to the PivotDataField.ShowValuesWithCalculation method as a parameter, or call the PivotDataField.ShowValuesWithoutCalculation method.

The following example demonstrates how to calculate the difference in product sales between the current quarter and the previous quarter. Values in the data field are summarized using the "Sum" function.

The image below shows the result.

Is this topic helpful?​​​​​​​