How to: |
Given an aggregated input field and a negative offset, PREVIOUS retrieves the value in a prior row, within a sort break or the entire table. The reset point for the calculation is determined by the value of the PARTITION_ON parameter described in Specify the Partition Size for Simplified Statistical Functions.
Note: The values used in the retrieval 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.
PREVIOUS([prefix.]field, offset)
where:
Is one of the following optional aggregation operators to apply to the field before using it in the calculation:
Numeric or an alphanumeric field that contains all numeric digits.
The field to be used in the calculation.
Numeric
Is a negative number indicating the number of rows back from the current row to use for the retrieval.
The following request sets the PARITITON_ON parameter to TABLE and retrieves the value of the QUANTITIY_SOLD field two rows back from the current row.
SET PARTITION_ON=TABLE TABLE FILE wflite SUM QUANTITY_SOLD COMPUTE PREV = PREVIOUS(QUANTITY_SOLD,-2); 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 value of PREV in the first two rows is zero, as there are no prior rows for retrieval. From then on, each value of PREV is from the QUANTITY_SOLD value from two rows prior, with no reset points.