UC7 - Calculate Cumulated Values

This use case shows how to calculate cumulated values of sales in percentage and show them in a new series next to the main series, which shows the sum of sales per month.

See Also
MAP
SORT
RESULT SET
Defining Data Queries

Context: In this example, you want to have a processing graph with:

  • A SORT operator to sort dates in ascending order.
  • An AGGREGATE operator to calculate the sum of sales. It defines an input variable that you will use in the MAP operator to call the sum of sales.
  • A MAP operator to calculate the percentage for the cumulated values.

To get the delta revenue in percentage, you can configure the MAP operator as follows:

  1. Add a SORT operator and define input as variable.


  2. Link the SORT operator to an AGGREGATE operator and configure it to calculate the sum of sales.
    1. In Operator input variable, select input.
    2. In the Aggregation section, select Single aggregator.
    3. For Aggregator, select Sum.
    4. In Expression, enter input.sales.


  3. Link the AGGREGATE operator to a TO VARIABLE operator, and define a totalSales variable.
  4. Link the SORT operator to a MAP operator and configure it as follows.
    1. Select Use State.
    2. In Variables, add a sum variable. For its type, enter Decimal<2> and enter 0 as value.
    3. In Updates, select the sum variable, and enter the expression sum + input.sales
    4. For Output, specify the following expression: { ...input, sum:(sum/@totalSales) * 100}


  5. Link the MAP operator to a RESULT SET operator.
    1. In the Fields section, enter:

      • date and input.date as expression.
      • sales and input.sales as expression.
      • sumPercentage and input.sum as expression.


    2. In the Dimensions section, add a dimension to sort value by ascending order.



    3. In the Aggregations section, add a Custom aggregation.
    4. In Variables, add a test variable. For its type, enter Decimal<2> and enter 0 as value.
    5. In Updates, select the test variable, and enter the expression test + sales
    6. For Output, specify the following expression: test

Result: