Informix Error -4361: Group aggregates can occur only in AFTER GROUP clauses.
Cause and resolution
Group aggregates can occur only in AFTER GROUP clauses.
The aggregate functions that apply to a group of rows (GROUP COUNT, GROUP PERCENT, GROUP SUM, GROUP AVG, GROUP MIN, and GROUP MAX) can only be used at the point in the report when a complete group has been processed, namely, in the AFTER GROUP control block. Make sure that the AFTER GROUP statement exists and was recognized. If you need the value of a group aggregate at another time (for instance, in a PAGE TRAILER control block), you can save it in a global variable with a LET statement in the AFTER GROUP control block.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-4361 fires when a group aggregate (GROUP COUNT, GROUP PERCENT, GROUP SUM, GROUP AVG,
GROUP MIN, GROUP MAX) is used outside an AFTER GROUP control block — per the official
guidance, these are only meaningful once a complete group has been processed.
- A group aggregate used outside an
AFTER GROUPcontrol block, per the official guidance — the direct, only cause. - A missing or unrecognized
AFTER GROUPstatement, per the official guidance — a related possible cause.
Solutions / Resolution
- Confirm the
AFTER GROUPstatement exists and was recognized, per the official guidance. - If the group aggregate's value is needed elsewhere (e.g. a
PAGE TRAILER), save it in a global variable with aLETstatement insideAFTER GROUP, per the official guidance.
Examples
Using a group aggregate outside AFTER GROUP
FORMAT
ON EVERY ROW
PRINT GROUP SUM(rec.amount)
-- -4361: group aggregates only work in AFTER GROUP
Corrected
FORMAT
AFTER GROUP OF rec.customer
LET group_total = GROUP SUM(rec.amount)
PRINT group_total
Diagnostic Checks
- Check every group aggregate's location, and confirm it's inside an
AFTER GROUPblock, saving its value to a global variable first if needed elsewhere.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -4361 in this set yet.
A group aggregate is used outside AFTER GROUP — move it inside, saving its value to a global
variable if it's needed elsewhere in the report.