skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • NEW: Design Kits for Figma
    • Online Training
    • Document Processing Library
    • Embedded Reporting for web and desktop

    Web

    Kendo UI UI for jQuery UI for Angular UI for React UI for Vue UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX

    Mobile

    UI for .NET MAUI

    Document Management

    Telerik Document Processing

    Desktop

    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF

    Reporting

    Telerik Reporting Telerik Report Server

    Testing & Mocking

    Test Studio Test Studio Dev Edition Telerik JustMock

    CMS

    Sitefinity

    UI/UX Tools

    ThemeBuilder Design System Kit Templates and Building Blocks

    Debugging

    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Everywhere Reporter FiddlerCore

    Free Tools

    VB.NET to C# Converter Testing Framework
    View all products
  • Overview
  • Demos
    • What's New
    • Roadmap
    • Release History
  • Support and Learning

    • Support and Learning Hub
    • First Steps
    • Docs
    • Demos
    • Virtual Classroom
    • Use Reports in Applications
    • System Requirements
    • Forums
    • Videos
    • Blogs
    • Submit a Ticket
    • FAQs
  • Pricing
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Downloads
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now
Search all

Interface IAggregateFunction

Provides custom (user-defined) implementation for aggregate function.

Namespace: Telerik.Reporting.Expressions
Assembly: Telerik.Reporting.dll

Syntax

public interface IAggregateFunction
Remarks

Implement this interface to provide custom logic when aggregating values over a set of rows from the data source. Apply the AggregateFunctionAttribute class to the aggregate implementation in order to set the name and description of the aggregate function. If no AggregateFunctionAttribute is defined, the name of the aggregate function is the name of the actual type that implements the IAggregateFunction interface. The word "Aggregate" is trimmed from the type name if it ends with it.

Examples

This example shows how to implement user-defined aggregate.

[AggregateFunction(Description = "Concatenation aggregate. Output: (value1, value2, ...)", Name = "Concatenate")]
class ConcatenateAggregate : IAggregateFunction
{
    string result;

    public void Accumulate(object[] values)
    {
        // The aggregate function expects one parameter
        object value = values[0];

        // null values are not aggregated
        if (null == value)
        {
            return;
        }

        // The actual accumulation
        if (this.result.Length > 0)
        {
            result += ", ";
        }
        this.result += value.ToString();
    }

    public object GetValue()
    {
        return string.Format("({0})", this.result);
    }

    public void Init()
    {
        // Add aggregate function initialization code here if needed
        this.result = string.Empty;
    }

    public void Merge(IAggregateFunction aggregateFunction)
    {
        ConcatenateAggregate aggregate = (ConcatenateAggregate)aggregateFunction;

        if (aggregate.result.Length > 0)
        {
            if (this.result.Length > 0)
            {
                result += ", ";
            }
            this.result += aggregate.result;
        }
    }
}
 _
Class ConcatenateAggregate
    Implements IAggregateFunction
    Private result As String

    Public Sub Accumulate(ByVal values As Object()) Implements IAggregateFunction.Accumulate
        ' The aggregate function expects one parameter
        Dim value As Object = values(0)

        ' null values are not aggregated
        If value Is Nothing Then
            Return
        End If

        ' The actual accumulation
        If Me.result.Length > 0 Then
            result += ", "
        End If
        Me.result += value.ToString()
    End Sub

    Public Function GetValue() As Object Implements IAggregateFunction.GetValue
        Return String.Format("({0})", Me.result)
    End Function

    Public Sub Init() Implements IAggregateFunction.Init
        ' Add aggregate function initialization code here if needed
        Me.result = String.Empty
    End Sub

    Public Sub Merge(ByVal aggregateFunction As IAggregateFunction) Implements IAggregateFunction.Merge
        Dim aggregate As ConcatenateAggregate = DirectCast(aggregateFunction, ConcatenateAggregate)

        If aggregate.result.Length > 0 Then
            If Me.result.Length > 0 Then
                result += ", "
            End If
            Me.result += aggregate.result
        End If
    End Sub
End Class

Methods

Accumulate(Object[])

Accumulates the passed values in the aggregate.

Declaration
void Accumulate(object[] values)
Parameters
System.Object[] values

The values that will be accumulated on a single accumulation operation. The length of the values array equals to the number of parameters that the defined aggregate expects (most common one).

GetValue()

Gets the value that the aggregate instance keeps currently accumulated.

Declaration
object GetValue()
Returns
System.Object

Returns the currently accumulated value.

Init()

Initializes the aggregate function instance. Implement to set the aggregate in its initial state ready to accumulate and merge values.

Declaration
void Init()

Merge(IAggregateFunction)

Merges another instance of the same aggregate function into the current instance. Implement this method to allow the reporting engine to merge the two resulting aggregates coming from two subsets of the aggregated data source rows.

Declaration
void Merge(IAggregateFunction aggregateFunction)
Parameters
IAggregateFunction aggregateFunction

Another instance of the same aggregate function that will be merged in the current instance.

Getting Started
  • Install Now
  • Online Demos
Support Resources
  • Documentation
  • Knowledge Base
  • Videos
  • Reporting Samples Repository
  • Reporting Release History
Community
  • Forums
  • Blogs
  • Reporting Feedback Portal

Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.