How to show difference between two fields?

from(bucket: “a_bucket”)

|> range(start:-100d)

|> filter(fn: (r) =>

  r._measurement == "closes" and

  (r._field == "A" or r._field == "B")

)

|> yield()

above would show values of “A” and “B” and now I want to show the difference between “A” and “B”; how?

Maybe just use a Binary operation Transform like this?

thanks a lot; this is exactly what I want to;
in addition, shall I modify “backend_02” and “backend_01” by adding variables; for examples, I define two “Text box”/“Custom” variables: “text_box_1” and “text_box_2” like below:


I want to edit them directly;

Glad the binary transformation will do the trick.

No idea if adding variables will work, so give it a try and post the results here.

Just a question :slight_smile:

I have two graphs:
one for a OUT temp and one for IN temp (from fluxDB and a csv file)
but using the (
Tranformation data:
Add Field form Calculation
Mode Binary operation and selecting the two series,
)
I don’see the new (the result of the difference operation) one.

MAYBE the datas must be “formatted” with exactly same time
(one of the series has fewer samples)?
Hope this is not OT.
Thank you.

Hi @graf0

Yes, in general, if you want to do a math operation on two series, they should have identical timestamps. If that is not the case or is not possible, in Flux you can use the data.truncate() function.

Thank you !