Problems / Running Balance With Resets / Editorial
is_reset
SUM(is_reset)
0.00
(account_id, segment)
Window functions accumulate; they don't conditionally *reset* — there is no SUM(...) RESTART WHEN clause. The universal workaround is to materialize the reset as a partition key: derive a segment id with the flag-prefix-sum trick, and the engine's own partition isolation does the forgetting. This two-window composition (one window to *define* groups, a second to *aggregate within* them) is the load-bearing pattern behind sessionization, streak analysis, and every "running X that restarts on Y" requirement.
SUM(...) RESTART WHEN
Solve Running Balance With Resets yourself →