Purpose
Demo ZCL_XTT_DEMO_052 calculates parent values from child rows. XTT supports both an ABAP event for custom logic and declarative aggregation functions for common totals.
Calculation in ABAP
Use the PREPARE_TREE event when the parent calculation is application-specific:

After casting the generic references, loop over the children and calculate the required values.

The handler is flexible, but its rules are not visible in the template.
Declarative aggregation
For standard calculations, use ;func= with SUM, AVG, COUNT, or FIRST.

The function may be declared once for a complete level; it does not need to be repeated in every marker.
In the example, level 0 uses AVG, while level 1 uses SUM.
- FIRST takes the value from the first child
- COUNT returns their number

You can combine programmatic and declarative calculations. Prefer template functions when they express the rule clearly; use the event when they do not.