Moving average to get average EUR/kWh price


I am currently using Grafana and InfluxDB in HASSIO. I have measurements of the total used kWh of my home over its lifetime that is slowy increasing. The rate I pay per kWh is varying per hour. My power provider calculates my average kWh price at each month. I would like to know what this was in the past months and what it will be for the current running month. For getting the previous months I simply make a query that gets the total difference between the kWh at the beginning of the months and the kWh at the end of the month as follows:

SELECT difference(mean(“value”)) FROM “kWh” WHERE (“entity_id” = ‘energy_consumed_tariff_1’) AND $timeFilter GROUP BY time(1M) fill(previous)

I do the same for the runnings costs

SELECT difference(mean("value")) FROM "EUR" WHERE ("entity_id" = 'energy_consumed_tariff_1_cost') AND $timeFilter GROUP BY time(1M) fill(previous)

These two values can be divided by each other to get my average kWh price.

However, for the current month I need to get a weighted average of the kWh used times the price per kwh at that time.

Can anyone help with that?

ps. I also have a database with the hourly price in EUR/kWh.