Sensor resetting just before midnight

I have a card that shows my daily energy profit or cost. It works for the current day, but it is wrong for the previous days. I think it is due to one of the sensors being reset just before midnight. This makes the ‘last’ option in the card incorrect. I have fixed the, sensor.ts_todays_electricity_fixed_export_compensation by using max, as this value always goes up. The issue is, sensor.ts_todays_electricity_credit_or_debit can go down and up during the day.

Screenshot 2023-10-16 at 09.01.23

Any thoughts what I can do here?