Custom Aggregate Function: AggCountIf()
Review the documentation on Custom Aggregate Functions for full details on developing and implementing this function.
| Description | Returns the count of values of dataToAggregatewith a corresponding truecondition.  Only those records with a trueconditionare included in the count.conditionis true if it meets any one of the following conditions:it is the Boolean type trueit is the string “true“it is the function True()it is a non-zero number, or can be converted to a non-zero number
 | 
|---|
| Arguments | dataToAggregate: the data field to count, accepts data fields or cell references. Required.condition: a Boolean value or expression that when true will include this item in the count. Required.recordLevel: indicates whether to aggregate by recordLevel (true) or entity level (false). Optional, defaults true if not provided.
 | 
|---|
| Namespaces | WebReports.Api.CommonWebReports.Api.Custom
 | 
|---|
| Example | To return the number of current products: AggCountIf({Products.ProductName}, Not({Products.Discontinued}))60
 To return the number of orders whose revenue was greater than $15,000.00:
 AggCountIf({Orders.OrderId}, if({OrderDetails.Revenue} > 15000))5
 | 
|---|
Program Code
public class AggCountIf : ICustomAggregator
{
    int count = 0;
  
	public void AddValue(SessionInfo sessionInfo, object value, params object[] args)
	{
        bool isTrue;
        double number;
        if ((bool.TryParse(args[0].ToString(), out isTrue) && isTrue) || 
            (double.TryParse(args[0].ToString(), out number) && number != 0))
            ++this.count;
	}
  
	public object Result(SessionInfo sessionInfo)
	{
		return this.count;
	}
}