| Working with FlexReport > Grouping Data > Adding Subtotals and Other Aggregates |
C1FlexReport 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.
Dim f1 As 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) Dim tf As 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)
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);
