Sum the max value of an entity of every day in grafana

Hello!
I have a value (from HA entity) that stores the total daily power consumed. This value is written all day long in the database, starting small at the beginning of the day and growing during the day. At midnight the machine zeroes the value by starting a new daily production.
So I need grafana to present me a sum of the maximum values ​​obtained for each day, according to the selected period.
So I can calculate how many tons I have in 1 day or 1 week or even 1 year.
This is the table structure:

SELECT mean(“value”) FROM “кВт” WHERE (“entity_id” = ‘monthly_total’) AND timeFilter GROUP BY time(__interval) fill(null)