# Calculation within one measurement with multiple tags

Hello,
I am looking for help with an (at least for me) complex problem:

I am measuring multiple power outlets and write the values into one measurement “total_consumption” with a specific tag for each consumer.
Additionally, I am measuring the overall consumption direktly at the power meter.

Now I want to calculate the remainder between the sum of the individual consumers and the total consumption.

The current Flux query looks like this:

``````import "timezone"
import "experimental"
import "date"
option location = timezone.location(name: "Europe/Berlin")
from(bucket: "smarthome")
|> range(start: experimental.subDuration(d: 60m, from: v.timeRangeStart), stop: experimental.addDuration(d: 60m, to: v.timeRangeStop))
|> filter(fn: (r) => r["_measurement"] == "total_consumption")
|> filter(fn: (r) => r["sensor"] == "Kuehlschrank" or r["sensor"] == "Luftentfeuchter" or r["sensor"] == "Mediarack" or r["sensor"] == "PC" or r["sensor"] == "Waschmaschine" or r["sensor"] == "Serverschrank" or r["sensor"] == "Kronleuchter" or r["sensor"] == "Waschbecken")
|> aggregateWindow(every: 60m, period: 60m, fn: last, createEmpty: true)
|> difference(nonNegative: true, columns: ["_value"])
``````

The panel looks like this:

How do I add the “rest” value?

Welcome to the community. if I understand correctly the “rest” value is the original value before applying the difference?

To clarify, if I add this as second query

``````import "timezone"
import "experimental"
import "date"
option location = timezone.location(name: "Europe/Berlin")
from(bucket: "smarthome")
|> range(start: experimental.subDuration(d: 60m, from: v.timeRangeStart), stop: experimental.addDuration(d: 60m, to: v.timeRangeStop))
|> filter(fn: (r) => r["_measurement"] == "total_consumption")
|> filter(fn: (r) => r["sensor"] == "Stromzaehler")
|> aggregateWindow(every: 60m, period: 60m, fn: last, createEmpty: true)
|> difference(nonNegative: true, columns: ["_value"])
``````

I get the following:

But since all the other elements (PC, Waschmaschine etc.) are only portions of “Stromzaehler” it makes no sense to just stack everything.