How to calculate the self-consumption of a PV system

I have a small PV balcony system from which I write the current daily production into InfluxDB. I also write the current overproduction of the PV system that I feed into the public grid into InfluxDB. Now I would like to calculate my own consumption (current daily production - public grid feed-in) from these two values.
Here is my current Querry:
from(bucket: “edomi”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “PV.Ueberschuss_Netzeinspeisung_errechnet_3” or r[“_measurement”] == “Außen.Balkon.Balkonsolar.TagesErtrag_aktuell”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> keep(columns: [“_measurement”, “_time”, “_value”])
|> fill(usePrevious: true)
|> pivot(rowKey:[“_time”], columnKey: [“_measurement”], valueColumn: “_value”)
|>difference()
|> aggregateWindow(every: 1d, fn: sum, timeSrc: “_start”)

and get this error by combining the data with pivot: “runtime error: column “_value” does not exist”. Can someone help me solve the problem?

Here the data without the pivot:

Can’t anyone help me?

Hello @Sargon,
I apologize for the delay.

If you pivot you want to then use a map to perform the difference

Here is my current Querry:
from(bucket: “edomi”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “PV.Ueberschuss_Netzeinspeisung_errechnet_3” or r[“_measurement”] == “Außen.Balkon.Balkonsolar.TagesErtrag_aktuell”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> keep(columns: [“_measurement”, “_time”, “_value”])
|> fill(usePrevious: true)
|> pivot(rowKey:[“_time”], columnKey: [“_measurement”], valueColumn: “_value”)
|> map(fn: (r) => ({r with _value: r.PV.Ueberschuss_Netzeinspeisung_errechnet_3 * Außen.Balkon.Balkonsolar.TagesErtrag_aktuell}))

You might also need to

|> group()

before the pivot :slight_smile:
I hope that helps. Sorry again for the delay.