FlexPivot for WPF | ComponentOne
Data Blending / Grouping
In This Topic
    Grouping
    In This Topic

    Grouping allows you to summarize and analyze large chunks of data. It is a unique feature in the FlexPivotGrid control that enables you to organize data in groups based on a specific set of criteria. The FlexPivotGrid control allows you to group the data by any field value.

    You can perform range grouping programmatically. For this, you can use Range property of the PivotField class, which defines the type of grouping values using the RangeType enumeration. The following sections discuss how to perform range grouping in FlexPivot by setting different range types, such as string, number, format and fiscal year.

    String Grouping

    You can perform range grouping by string fields programmatically using the RangeType property and setting the range type to AlphabeticalIgnoreCase to group the range alphabetically ignoring the case as shown in the following code.

    C#
    Copy Code
    //Nested groups: By Alphabet, then by Product
    flexPivotPage.FlexPivotEngine.RowFields.Add("ProductName");
    flexPivotPage.FlexPivotEngine.RowFields.Add("ProductName");
    flexPivotPage.FlexPivotEngine.ColumnFields.Add("OrderDate");
    flexPivotPage.FlexPivotEngine.ValueFields.Add("UnitPrice");
    flexPivotPage.FlexPivotEngine.RowFields[0].Caption = "Product: Group by first letter";
    flexPivotPage.FlexPivotEngine.RowFields[0].Range.RangeType = RangeType.AlphabeticalIgnoreCase;
    flexPivotPage.FlexPivotEngine.RowFields[1].Caption = "Product";
    

    Back to Top

    Numeric Grouping

    You can perform range grouping by numeric fields at run-time as well as through code.

    Range Grouping by Numbers at Run-Time

    Complete the following steps to implement grouping by numeric fields in FlexPivotGrid control.

    The data after grouping by numeric range appears similar to the image given below.

    RangebyNumber

    Range Grouping by Numbers with Code

    You can perform range grouping by numeric fields using the RangeType property and setting the range type to Numeric to group the range numerically. You can also specified ranges in small numbers using the NumericStep property as shown in the following code.

    C#
    Copy Code
    //Grouping by numeric range
    flexPivotPage.FlexPivotEngine.RowFields.Add("UnitPrice");
    flexPivotPage.FlexPivotEngine.ValueFields.Add("UnitPrice");
    flexPivotPage.FlexPivotEngine.RowFields[0].Caption = "Price group";
    flexPivotPage.FlexPivotEngine.RowFields[0].Range.RangeType = RangeType.Numeric;
    flexPivotPage.FlexPivotEngine.RowFields[0].Range.NumericStep = 50;
    flexPivotPage.FlexPivotEngine.ColumnFields.Add("Country");
    

    Back to Top

    Date Grouping

    You can perform range grouping by date fields programmatically using the RangeType property and setting the range type to Format to group the dates in a specific format, such as "yyyy" format for displaying the year, as shown in the following code.

    C#
    Copy Code
    //By format: group by year, month or day
    flexPivotPage.FlexPivotEngine.RowFields.Add("OrderDate");
    flexPivotPage.FlexPivotEngine.RowFields[0].Caption = "Year";
    flexPivotPage.FlexPivotEngine.RowFields[0].Range.RangeType = RangeType.Format;
    flexPivotPage.FlexPivotEngine.RowFields[0].Format = "yyyy";
    flexPivotPage.FlexPivotEngine.ColumnFields.Add("Country");
    flexPivotPage.FlexPivotEngine.ValueFields.Add("ExtendedPrice");
    

    Back to Top

    Fiscal Year Grouping

    You can perform range grouping by Fiscal Year programmatically using the RangeType property and setting the range type to FiscalYear to group the range according to the fiscal year as shown in the following code. In the following example, we set the number of first month in the fiscal year using the FiscalYearFirstMonth property.

    C#
    Copy Code
    //Range Grouping by Fiscal year
    flexPivotPage.FlexPivotEngine.RowFields.Add("OrderDate");
    flexPivotPage.FlexPivotEngine.ColumnFields.Add("Country");
    flexPivotPage.FlexPivotEngine.ValueFields.Add("ExtendedPrice");
    flexPivotPage.FlexPivotEngine.RowFields[0].Range.RangeType = RangeType.FiscalYear;
    flexPivotPage.FlexPivotEngine.RowFields[0].Range.FiscalYearFirstMonth = 4;
    flexPivotPage.FlexPivotEngine.RowFields[0].Format = "FY {yyyy}";
    flexPivotPage.FlexPivotEngine.RowFields[0].Caption = "Fiscal Year";
    

    Back to Top