RUNNING_MIN: Calculating a Minimum Over a Group of Rows

How to:

Given an aggregated input field and an offset, RUNNING_MIN calculates the minimum of the values between the current row of the report output and one or more prior rows, within a sort break or the entire table. The reset point for the calculation is determined by the sort field specified, the entire table, or the value of the PARTITION_ON parameter described in Specify the Partition Size for Simplified Statistical Functions.

Syntax: How to Calculate Running Minimum Between the Current and a Prior Value of a Field

RUNNING_MIN(field, reset_key, lower) 

where:

field

Numeric or an alphanumeric field that contains all numeric digits.

The field to be used in the calculation.

reset_key

Identifies the point at which the running minimum restarts. Valid values are:

Note: The values used in the calculations depend on the sort sequence (ascending or descending) specified in the request. Be aware that displaying a date or time dimension in descending order may produce different results than those you may expect.

lower

Is the starting point in the partition for the running minimum. Valid values are:

  • A negative number, which identifies the offset from the current row.
  • B, which specifies the beginning of the sort group.

Example: Calculating a Running Minimum

The following request calculates a running minimum of QUANTITY_SOLD within the PRODUCT_CATEGORY sort field (the sort break defined by SET PARTITION_ON = PENULTIMATE), always starting from the beginning of the sort break.

SET PARTITION_ON=PENULTIMATE
TABLE FILE wf_retail_lite
SUM QUANTITY_SOLD
COMPUTE RMIN = RUNNING_MIN(QUANTITY_SOLD,PRESET,B);
BY PRODUCT_CATEGORY
BY PRODUCT_SUBCATEG
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END

The output is shown in the following image. The first value for RMIN is the value in the Accessories category for Quantity Sold, as there is no prior value. The second value for RMIN is the value from the first row again (Charger), as that is smaller than the value in the second row. The third is the same again, as it is still the smallest. Then, the calculations start over for Camcorder, which is the reset point.