Aggregate Functions PivotData C# examples
PivotData OLAP library implements common summary functions: count, count unique, sum, average, min, max, variance/stddev, quantile/median, mode, formula.
It is possible to implement custom aggregator if needed.
Aggregate functions
In PivotData library aggregator is represented by IAggregatorFactory
components that
can create individual IAggregator
accumulators.
Library implements the following aggregate functions:
Factory component | Type of Value |
Description | Example |
---|---|---|---|
CompositeAggregatorFactory | object[] | Used for collecting several measures; accepts list of aggregator factories. |
new CompositeAggregatorFactory( new CountAggregatorFactory(), new SumAggregatorFactory("amount") ) |
CountAggregatorFactory | uint | Counts number of rows from facts table |
new CountAggregatorFactory() |
CountUniqueAggregatorFactory | int | Counts number of unique values from specified facts table column | new CountUniqueAggregatorFactory( "company_title") |
SumAggregatorFactory | decimal | Computes the sum of the specified column values from facts table |
new SumAggregatorFactory("amount") |
MinAggregatorFactory | (type of specified field) | Computes the minimum of the specified column values from facts table |
new MinAggregatorFactory("age") |
MaxAggregatorFactory | (type of specified field) | Computes the maximum of the specified column values from facts table |
new MaxAggregatorFactory("age") |
AverageAggregatorFactory | decimal | Computes the average of the specified column values from facts table |
new AverageAggregatorFactory("age") |
ListUniqueAggregatorFactory | ICollection | Collects only unique values from specified facts table column |
new ListUniqueAggregatorFactory("age") |
ListAggregatorFactory | ICollection | Collects all references (or values if field is specified) to the source fact objects (like LINQ GroupBy). |
new ListAggregatorFactory() new ListAggregatorFactory("name") |
VarianceAggregatorFactory | double | Computes mean/variance/sample variance/standard deviation/sample std-dev |
new VarianceAggregatorFactory( "exchange_rate", VarianceAggregatorValueType.SampleStdDevValue) |
QuantileAggregatorFactory | decimal | Computes specified quantile (median with 0.5 value) |
new QuantileAggregatorFactory("age",0.5M) |
ModeAggregatorFactory | object or object[] (if multimodal) | Computes a value(s) that appears most often. |
new ModeAggregatorFactory("age") |
FormulaAggregatorFactory | (depends on formula result) | Compute custom formula value by arguments of specified aggregators |
new FormulaAggregatorFactory( "Actual/Estimated", (argValues) => { var actual = Convert.ToDecimal(argValues[0]); var estimated = Convert.ToDecimal(argValues[1]); return actual/estimated; }, new [] { new SumAggregatorFactory("actual"), new SumAggregatorFactory("estimated") } ) |
It is possible to use custom aggregator (single-pass summary function) by implementing IAggregatorFactory/IAggregator interfaces.