In DXperience v10.1, the WPF Pivot Grid Control has caught up with it’s WinForms counterpart feature-wise.
If you were waiting for it to start your new WPF app wait no more. Let’s take a closer look at some of the features.
Getting Started
Pivoting is most fun when you understand the data (the fact table) you are working with.
Let’s use a basic product-orders that all are familiar with.
To mark this up:
<Window x:Class="WpfApplication1.MainWindow"
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">
<Grid>
<dxpg:PivotGridControl x:Name="pivotGrid">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField FieldName="Extended Price" Caption="Price" Area="DataArea" AllowedAreas="DataArea" CellFormat="c"/>
<dxpg:PivotGridField FieldName="ProductName" Area="RowArea" Caption="Product" />
<dxpg:PivotGridField FieldName="OrderDate" Area="ColumnArea" Caption="Order Date"/>
<dxpg:PivotGridField FieldName="CategoryName" Area="FilterArea" Caption="Category"/>
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
</Grid>
</Window>
There are 3 data field areas (dimensions).
- ColumnArea – (Order Date)
- RawArea – (Product)
- DataArea – (Price)
the 4th one, FilterArea, does not participate in calculations, it is a placeholder for your filter fields.
Interval Grouping and Date Fields
In a lot of cases, cross-tabbing raw values is not very useful. This is especially true for the date fields.
While seeing the aggregates per date is applicable sometimes, in most cases however, it is much more interesting to see
values broken down by date parts. To help with that, there is a set of group interval functions.
public enum PivotGroupInterval {
...
Date,
DateDay,
DateDayOfWeek,
DateDayOfYear,
DateWeekOfMonth,
DateWeekOfYear,
DateMonth,
DateQuarter,
DateYear,
YearAge,
MonthAge,
WeekAge,
DayAge
...
}
For example to see the Price by OrderDate.Year we can use the DateYear group interval.
<dxpg:PivotGridControl x:Name="pivotGrid">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField FieldName="OrderDate" Area="ColumnArea" GroupInterval="DateYear" Caption="Year"/>
...
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
The Pivot Grid is not restricted to 3 dimensions. I can expand the OrderDate into 3: Year, Month, Day
<dxpg:PivotGridControl x:Name="pivotGrid">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField FieldName="CategoryName" Area="FilterArea" Caption="Category"/>
<dxpg:PivotGridField FieldName="Extended Price" Caption="Price" Area="DataArea" AllowedAreas="DataArea" CellFormat="c"/>
<dxpg:PivotGridField FieldName="ProductName" Area="RowArea" Caption="Product" />
<dxpg:PivotGridField FieldName="OrderDate" Area="ColumnArea" AllowedAreas="ColumnArea" GroupInterval="DateYear" Caption="Year"/>
<dxpg:PivotGridField FieldName="OrderDate" Area="ColumnArea" AllowedAreas="ColumnArea" GroupInterval="DateMonth" Caption="Month"/>
<dxpg:PivotGridField FieldName="OrderDate" Area="ColumnArea" AllowedAreas="ColumnArea" GroupInterval="DateDay" Caption="Day"/>
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
In 10.1 we have added a new Groups feature to better organize fields.
<dxpg:PivotGridControl x:Name="pivotGrid">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField FieldName="Extended Price" Caption="Price" Area="DataArea" AllowedAreas="DataArea" CellFormat="c"/>
<dxpg:PivotGridField FieldName="ProductName" Area="RowArea" Caption="Product" />
<dxpg:PivotGridField FieldName="OrderDate" Group="{Binding ElementName=PivotGridGroup1}" Area="ColumnArea" AllowedAreas="ColumnArea" GroupInterval="DateYear" Caption="Year"/>
<dxpg:PivotGridField FieldName="OrderDate" Group="{Binding ElementName=PivotGridGroup1}" Area="ColumnArea" AllowedAreas="ColumnArea" GroupInterval="DateMonth" Caption="Month"/>
<dxpg:PivotGridField FieldName="OrderDate" Group="{Binding ElementName=PivotGridGroup1}" Area="ColumnArea" AllowedAreas="ColumnArea" GroupInterval="DateDay" Caption="Day"/>
<dxpg:PivotGridField FieldName="CategoryName" Area="FilterArea" Caption="Category"/>
</dxpg:PivotGridControl.Fields>
<dxpg:PivotGridControl.Groups>
<dxpg:PivotGridGroup x:Name="PivotGridGroup1" Caption="Order Date" />
</dxpg:PivotGridControl.Groups>
</dxpg:PivotGridControl>
Fields within a group are collapsible so you can create pivot repots as drilled down as you want without loosing the ability to
aggregate by a specific interval.
Cheers
Azret