Example T555636
Visible to All Users

Pivot Grid for WPF - How to Specify Custom Summary Values for Total, Grand Total, and Ordinary Cells

This example demonstrates how to determine the value type when you calculate custom summary values.

Pivot Grid

Files to Review

Example Overview

Follow the steps below to create a custom summary.

  1. Create an ExpressionDataBinding object.
  2. Pass the following expression in its constructor as a parameter:
    Code
    iif(IsTotal([fieldColumnGroup]),'Grand Total',IsTotal([fieldRowGroup]),'Grand Total',IsTotal([fieldColumn]),'Total',IsTotal([fieldRow]),'Total',Sum([Data]))
  3. Assign the ExpressionDataBinding instance to the fieldData field's DataBinding property.

Documentation

More Examples

How to Create a Custom Summary to Display the Distinct Value Count

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

WpfApplication1/MainWindow.xaml
XAML
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid" x:Class="WpfApplication1.MainWindow" xmlns:local="clr-namespace:WpfApplication1" xmlns:e="http://schemas.microsoft.com/expression/2010/interactivity" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:MyDataContext/> </Window.DataContext> <Grid> <dxpg:PivotGridControl Name="pivotGridControl1" DataSource="{Binding Path=Data}" DataProcessingEngine="Optimized"> <dxpg:PivotGridControl.Fields> <dxpg:PivotGridField Area="RowArea" Name="fieldRowGroup"> <dxpg:PivotGridField.DataBinding> <dxpg:DataSourceColumnBinding ColumnName="RowGroup"/> </dxpg:PivotGridField.DataBinding> </dxpg:PivotGridField> <dxpg:PivotGridField Area="RowArea" Name="fieldRow"> <dxpg:PivotGridField.DataBinding> <dxpg:DataSourceColumnBinding ColumnName="Row"/> </dxpg:PivotGridField.DataBinding> </dxpg:PivotGridField> <dxpg:PivotGridField Area="ColumnArea" Name="fieldColumnGroup"> <dxpg:PivotGridField.DataBinding> <dxpg:DataSourceColumnBinding ColumnName="ColumnGroup"/> </dxpg:PivotGridField.DataBinding> </dxpg:PivotGridField> <dxpg:PivotGridField Area="ColumnArea" Name="fieldColumn"> <dxpg:PivotGridField.DataBinding> <dxpg:DataSourceColumnBinding ColumnName="Column"/> </dxpg:PivotGridField.DataBinding> </dxpg:PivotGridField> <dxpg:PivotGridField Area="DataArea" Name="fieldData"> <dxpg:PivotGridField.DataBinding> <dxpg:ExpressionDataBinding Expression="iif( IsTotal([fieldColumnGroup]),'Grand Total', IsTotal([fieldRowGroup]),'Grand Total', IsTotal([fieldColumn]),'Total', IsTotal([fieldRow]),'Total', Sum([Data]))"/> </dxpg:PivotGridField.DataBinding> </dxpg:PivotGridField> </dxpg:PivotGridControl.Fields> </dxpg:PivotGridControl> </Grid> </Window>
WpfApplication1/MyDataContext.cs(vb)
C#
using System; using System.Data; namespace WpfApplication1 { public class MyDataContext { public MyDataContext() { Data = GetData(); } public DataTable Data { get; private set; } DataTable GetData() { DataTable dt = new DataTable(); Random rnd = new Random(); dt.Columns.Add("RowGroup", typeof(string)); dt.Columns.Add("Row", typeof(string)); dt.Columns.Add("ColumnGroup", typeof(string)); dt.Columns.Add("Column", typeof(string)); dt.Columns.Add("Data", typeof(int)); for(int rowGroup = 1; rowGroup < 5; rowGroup++) for(int row = 1; row < 5; row++) for(int columnGroup = 1; columnGroup < 5; columnGroup++) for(int column = 1; column < 5; column++) dt.Rows.Add( "Row Group" + rowGroup, "Row" + row, "Column Group" + columnGroup, "Column" + column, rnd.Next(100)); return dt; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.