FlexReport for .NET | ComponentOne
Reports in WinForms / Group Data / Subtotals and Aggregates
In This Topic
    Subtotals and Aggregates
    In This Topic

    FlexReport supports aggregate expressions in all its calculated fields. The aggregate expressions includes aggregates - Sum, Min, Max, Avg, Count, Range, Var, and so on.

    All aggregate functions take an expression as an argument and evaluate it within a scope that is determined by their position in the report. For example, aggregates in group headers or footers have the scope of the group. Aggregates in the report header or footer have the scope of the entire report.

    For example, the following aggregate expression would return the sum of all values in the Sales field for the scope of the aggregate (group or report): Sum(Sales)

    The following aggregate expression would return the total amount of sales taxes paid for all values in the report (assuming an 8.5% sales tax):Sum(Sales * 0.085)

    The following example uses Count aggregate to calculate number of records for employees falling under a designation.

    1. Add the following code in the check box event (c1CheckBox1_CheckedChanged) created in the sample Group Data.
      C#
      Copy Code
      Field f1 = new Field();
       f1.Name = "CountRecords";
       f1.Text = "Count(GrpTitle)";
       f1.Left = 2000;
       f1.Top = 500;
       f1.Width = c1FlexReport1.Layout.Width - 2000;
       f1.Height = 400;
       f1.Align = FieldAlignEnum.LeftMiddle;
       f1.MarginLeft = 100;
       f1.Calculated = true;
       f1.Visible = true;
       f1.BackColor = Color.Yellow;
       f1.Font.Bold = true;
       f1.Font.Size = 10;
       s.Fields.Add(f1);
      
      TextField tf = new TextField();
       tf.Name = "Text";
       tf.Text = "Number Of Records: ";
       tf.Left = 0;
       tf.Top = 500;
       tf.Width = c1FlexReport1.Layout.Width - f1.Width;
       tf.Height = 400;
       tf.Align = FieldAlignEnum.LeftMiddle;
       tf.Font.Bold = true;
       tf.Font.Size = 10;
       tf.BackColor = Color.Transparent;
       tf.BackColor = Color.Yellow;
       tf.MarginLeft = 100;
       tf.Visible = true;
       s.Fields.Add(tf);
      
    2. Run the project. Click 'Employees' button to render the report.
    3. Click 'Group Report by Title' checkbox to view grouping in the report. Observe that Number of Records are calculated for each group.

    Count in FlexReport