Exago Logo
Generic filters
Exact matches only

Custom Aggregate Function: AggSumIf()

Review the documentation on Custom Aggregate Functions for full details on developing and implementing this function.

Description Returns the sum of values of dataToAggregate with a corresponding true condition.  Only those records with a true condition are included in the sum. condition is true if it meets any one of the following conditions:

  • it is the boolean type true
  • it is the string “true
  • it is the function True()
  • it is a non-zero number, or can be converted to a non-zero number
  • dataToAggregate: the data field to sum, accepts data fields or cell references. Required.
  • condition: a boolean value or expression that when true will include this item in the sum. Required.
  • recordLevel: indicates whether to aggregate by recordLevel (true) or entity level (false). Optional, defaults true if not provided.
  • WebReports.Api.Common
  • WebReports.Api.Custom
Example To return the total number of products ordered in quarter 4: AggSumIf({OrderDetails.Quantity}, If(QuarterNumber({Orders.OrderDate})=4))

Program Code

public class AggSumIf : ICustomAggregator
    double sum = 0;
	public void AddValue(SessionInfo sessionInfo, object value, params object[] args)
        // Treat non-numbers as 0
        double input;
        if (!double.TryParse(value.ToString(), out input))
        bool isTrue;
        double number;
        // true, "true", and non-zero numbers are valid truthy values
        if ((bool.TryParse(args[0].ToString(), out isTrue) && isTrue) ||
            (double.TryParse(args[0].ToString(), out number) && number != 0))
            this.sum += input;
	public object Result(SessionInfo sessionInfo)
		return this.sum;
Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Table of Contents