Custom Aggregate Function: AggDistinctSum()
Review the documentation on Custom Aggregate Functions for full details on developing and implementing this function.
Description | Returns the sum of only unique values in a series. |
---|---|
Arguments |
|
Namespaces |
|
References |
|
Example | AggDistinctSum({OrderDetails.Revenue}) |
Program Code
public class AggDistinctSum : ICustomAggregator { HashSet<Decimal> list = new HashSet<Decimal>(); public void AddValue(SessionInfo sessionInfo, object value, params object[] args) { Decimal curVal; if (value == null) curVal = 0; else if (!Decimal.TryParse(value.ToString(), out curVal)) { throw new WrAggregationException(@"Tried to take the sum of a set containing a non-number"); } this.list.Add(curVal); } public object Result(SessionInfo sessionInfo) { Decimal sum = 0; foreach (Decimal val in this.list) { sum += val; } return sum; } }