> ## Documentation Index
> Fetch the complete documentation index at: https://offthepace.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# trailing_sum

> Sum of `value_col` over observations STRICTLY BEFORE the current row.

Sum of `value_col` over observations STRICTLY BEFORE the current row. Same frame as trailing\_median -- deliberately so: 08b's forward-window auditor has ONE shape to whitelist, not one per aggregate. This is the aggregate a point-in-time RATE needs. A rate is not a median of per-period rates: it is sum(numerator) / sum(denominator) over the window, so that a 78-lap race carries more weight than a 44-lap one. Build it from two trailing\_sum calls sharing a frame, never from a trailing\_median of a ratio column. Returns NULL where fewer than `min_observations` valid observations precede the row -- which is what distinguishes "no prior history" (NULL, unknowable) from "prior history with no events" (0.0, a real measurement). Ship trailing\_observation\_count() alongside so the NULLs are explainable from the data rather than silent.

## Signature

```sql theme={null}
{{ trailing_sum(value_col, partition_by, order_by, lookback=none, frame='rows', min_observations=1, valid_condition=none) }}
```

## Returns

scalar expression composable in a SELECT list. Usage (int\_sc\_hazard\_history, 02d -- hazard as of the START of season S): SELECT \{\{ trailing\_sum('n\_any\_onsets', \['circuit\_slug'], \['season'], frame='range') }} / NULLIF(\{\{ trailing\_sum('racing\_laps', \['circuit\_slug'], \['season'], frame='range') }}, 0) AS any\_hazard\_per\_lap FROM per\_circuit\_season


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.