Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

By utilizing the aggregation and grouping features, you can establish groups within the Result Matrix and subsequently perform aggregation operations on these groups, such as SUM, COUNT, etc.

Table of Contents
minLevel1
maxLevel6
outlinefalse
styledisc
typelist
printabletrue

Supported Aggregations

  • AVG

  • COUNT

  • MAX

  • MIN

  • SUM

...

Code Block
languagegroovy
def groupByData = api.newMatrix()
             // Definition of result matrix (columns, rows).
             .withColumns('TextColumn1', 'TextColumn2', 'NumericColumn3', 'NumericColumn4')
             .withRows(rows)
             // Property `.withGroupBy` defines that the `TextColumn1` and `NumericColumn3` are used for group by (The order is important).                     
             .withGroupBy(['TextColumn1', 'NumericColumn3'])
             // Property `.withColumnAggregation` defines the values for subtotal rows that will be calculated as SUM.
             // Values are based on the group by definition (`NumericColumn3`). This definition is optional.
             // When not used, like e.g. for `TextColumn1`, there will be no aggregation calculated for the `TextColumn1`.
             .withColumnAggregation('NumericColumn3', SUM)
             // Property `.calculateGroupByData` is an end statement for group definition.
             // This statement is only used together with `.withColumnAggregation`.
             .calculateGroupByData()

Description

...

Definition of result matrix (columns, rows).

...

Property .withGroupBy defines that the TextColumn1 and NumericColumn3 are used for the group by (The order is important).

...

(

...

)

...

Info

Static import is required to use a predefined enum with aggregation types.

Code Block
languagegroovy
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType.AVG
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType.COUNT
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType.MAX
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType.MIN

...