Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [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: 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]Charts
    [Expand]Protection
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T298650.

The image below shows the result.

How would you rate this topic?​​​​​​​