How recalculate values in 'statistics' table

Prevention: https://community.home-assistant.io/t/how-to-prevent-entity-from-resetting-to-0/369363/2?u=tom_l