cumMax and cumMin functions in the Factory

The cumMax and cumMin functions are very similar, as they calculate the values in the same way, but return opposite ones.

  • The cumMax function returns the cumulative maximum of the column, which is the greatest value between the current value of the column and the previous values of the same column, evaluated within groups defined by the group parameter if required.

  • The cumMin function returns the cumulative minimum of the column, which is the lowest value between the current value of the column and the previous values of the same column, evaluated within groups defined by the group parameter if required.

These functions divide the column into rows and compares the values one by one: this means that, if our column is made up of 10 records, the functions will compare row 1, then row 1 and 2, then row 1; 2; 3, then row 1; 2; 3; 4, and so on.


Function and parameters

cumMax(column, group)

cumMin(column, group)

Parameter

Description

column

It identifies the column to which you want to apply the formula. The column parameter is mandatory.

group

It allows you to group the results by a certain column.


Example - cumMax

The following example uses the Bike sales dataset.

Description

Screenshot

In the example here, we want to fill the cumMax attribute with the cumulative maximum of the Order_Quantity attribute.

The formula to write is: cumMax($"Order_Quantity")

  • Going on with our data analysis, we want our cumulative maximum to be grouped by the Country attribute, so our formula will become:

  • cumMax($"Order_Quantity",$"Country")


Example - cumMin

The following example uses the Bike sales dataset.

Description

Screenshot

  • In the example here, we want to fill the cumMin attribute with the cumulative minimum of the Order_Quantity attribute.

  • The formula to write is:

  • cumMin($"Order_Quantity")

  • Going on with our data analysis, we want our cumulative minimum to be grouped by the Country attribute, so our formula will become:

  • cumMin($"Order_Quantity",$"Country")