Max value when condition is true

I would like to track total filament use from my 3d printer. As it shown down in the picture, variable filament_use it related to the specific job and it resets after its finished printing. Unfortunately , complete state comes after variable is already reset. So I would need a way to get max value of filament_use while condition=printing and then store that value when condition=complete.
Also I would like if I could reset that value for new filament change. Is that possible to do with the template or history_stats variable ? I guess if I could extract start/end time from condition and use that in the history_stats to get max value ? Then I could have separate template where I could somehow control the reset of the variable ?

Way easier than that.

Use a utility meter helper with no reset cycle defined. It will count up forever.

The utility meter has a calibrate service that you can use to set the count back to zero when you want to. e.g. Put the action in a button on your dashboard.

That will do. Cheers.