Article information
Article relates to
Telerik Reporting
Created by
Rossen Hristov
Last modified
12 April 2011
Last modified by
Peter
Init: Called every time the accumulation of values must start over for a new subset of records from the data source.
[AggregateFunction(Name = "CountDistinct", Description = "Defines an aggregate function to count distinct values.")]
public class CountDistinctAggregate : Telerik.Reporting.Expressions.IAggregateFunction
{
private System.Collections.Generic.List<
object
> distinctValues;
/// <
summary
>
/// Initializes the current aggregate function to its initial
/// state ready to accumulate and merge values.
/// </
remarks
/// This method is called every time the accumulation of values
/// must start over for a new subset of records from the data source.
public void Init()
this.distinctValues = new System.Collections.Generic.List<
>();
}
/// Accumulates new argument values to the current aggregate function.
/// This aggregate function accepts one argument:
/// number - a numeric value to accumulate to the aggregate function;
public void Accumulate(object[] values)
if (!distinctValues.Contains(values[0]))
distinctValues.Add(values[0]);
/// Merges the specified aggregate function to the current one.
param
name
=
"Aggregate"
/// Specifies an aggregate function to be merged to the current one.
/// This method allows the reporting engine to merge two accumulated
/// subsets of the same aggregate function into a single result.
public void Merge(IAggregateFunction aggregate)
// Accumulate the values of the specified aggregate function.
System.Collections.Generic.List<
> sums1 = ((CountDistinctAggregate)aggregate).distinctValues;
foreach(object o in sums1)
this.Accumulate(new object[] { o });
/// Returns the currently accumulated value of the aggregate function.
returns
/// The currently accumulated numeric value of the aggregate function.
public object GetValue()
return this.distinctValues.Count;
<
Expressions.AggregateFunction
(
Name:
"CountDistinct"
,
Description:
"Defines an aggregate function to count distinct values."
)> _
Public Class CountDistinctAggregate
Implements Telerik.Reporting.Expressions.IAggregateFunction
Private distinctValues As System.Collections.Generic.List(Of Object)
''' <
''' Initializes the current aggregate function to its initial state
''' ready to accumulate and merge values.
''' </
''' This method is called every time the accumulation of values must
''' start over for a new subset of records from the data source.
Sub Init() Implements Expressions.IAggregateFunction.Init
Me.distinctValues = New System.Collections.Generic.List(Of Object)()
End Sub
''' Accumulates new argument values to the current aggregate function.
''' This aggregate function accepts one argument:
''' number - a numeric value to accumulate to the aggregate function;
Sub Accumulate(ByVal values() As Object) Implements Expressions.IAggregateFunction.Accumulate
If Not distinctValues.Contains(values(0)) Then
distinctValues.Add(values(0))
End If
''' Merges the specified aggregate function to the current one.
''' Specifies an aggregate function to be merged to the current one.
''' This method allows the reporting engine to merge two accumulated
''' subsets of the same aggregate function into a single result.
Sub Merge(ByVal aggregate As Expressions.IAggregateFunction) Implements Expressions.IAggregateFunction.Merge
' Accumulate the values of the specified aggregate function.
Dim sums1 = DirectCast(aggregate, CountDistinctAggregate).distinctValues
For Each o As Object In sums1
Me.Accumulate(New Object() {o})
Next
''' Returns the currently accumulated value of the aggregate function.
''' The currently accumulated numeric value of the aggregate function.
Function GetValue() As Object Implements Expressions.IAggregateFunction.GetValue
Return Me.distinctValues.Count
End Function
End Class
Resources Buy Try