Grafana query: percentage of energy consumption at night

Dear community,
I have a utility_meter integration which generates two sensors measuring my power consumption for a specific device: one is during peak hours, the other one is during offpeak hours.
I am trying to display a gauge within Grafana, and I am quite lost with this query. I want the gauge to display the percentage of time I use the device at night compared to day use.
So basically, the value I am trying to calculate is equal to: offpeak / (peak+offpeak)
How to write it in the query?

Are you using Grafana with InfluxDB? If so i don’t think this is possible and it is the InfluxDB query language that is the limit. I tried to do something similar, calculating power from current and voltage, a while ago and ended up doing the calculation before i put the measurement in the database.

Hi @RobinSt, thanks for your answer.
Indeed, I am using Grafana with InfluxDB.
In my case, I am not sure how I can compute the value before putting it into the database.