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:
|
|---|---|
| Arguments |
|
| Namespaces |
|
| Example |
To return the total number of products ordered in quarter 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))
return;
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;
}
}