Skip to content

Period Totals

Period Totals (commonly referred to as YTD — year-to-date) are cumulative aggregates that sum payrun results across all periods from the start of the fiscal year through the current payslip month. In PayrollEngine, period totals are always computed at report time, never during payrun execution.


What a period total represents

For any wage type or collector, the period total for month N is:

PeriodTotal(N) = Σ ConsolidatedValue(m)   for m = 1..N

ConsolidatedValue(m) is the final, correction-inclusive value for period m returned by GetConsolidatedWageTypeResults. Consolidation means that if a prior period was recalculated due to a retro correction, only the corrected final value is returned — the intermediate original result is excluded.


Why period totals must not be computed in the payrun

Computing period totals inside wage type or collector expressions is explicitly prohibited in PayrollEngine regulations.

Performance: GetConsolidatedWageTypeResults executes one SQL query per period per employee. Called inside a payrun, this means hundreds of queries for a company with 12 periods and 50 employees — orders of magnitude more work than the payrun itself. Consolidated result queries aggregate across payrun jobs, join result tables, and apply de-duplication logic. They are expensive by design and must be used sparingly.

Correctness: A payrun result must be a pure function of the current period's inputs. Reading results from other periods inside a wage type expression creates a temporal dependency: the wage type value for March depends on January's stored result. When a retro correction re-executes January, the stored March value is now stale and cannot be automatically invalidated. The regulation would need to re-execute the current period again — creating a cascade that cannot terminate reliably.

Stale data: Even if the initial calculation succeeds, the stored YTD value becomes incorrect the moment any prior period is retroactively corrected. A report that reads the stored YTD field would show the wrong total. Because the report re-queries GetConsolidatedWageTypeResults fresh on every run, it always reflects the current state of all periods.


Relationship to retro corrections

When a retro correction changes a prior period, GetConsolidatedWageTypeResults returns the corrected value for that period. The period total is therefore always based on the corrected values — it automatically reflects all outstanding retro corrections without any special handling. See Retro Corrections for how the RetroValue column is derived separately.


See Also