How to calculate among different tags

Hi,

I have this base query:

`import "influxdata/influxdb/schema"
from(bucket: "Options")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "dailyVols")
  |> filter(fn: (r) => r["_field"] == "vol")
  |> filter(fn: (r) => r["expiry"] == "20230130" or r["expiry"] == "20230222")
  |> filter(fn: (r) => r["spotCode"] == "APPL")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> pivot(rowKey:["_time"], columnKey: ["expiry"], valueColumn: "_value")
  |> map(fn: (r) => ({ _value: r.20230130 + r.20230222}))

what i want is to do some calculations among different tags across the same field and timestamps. But finally i got this error, could anybody helps? Thanks!

error @10:45-10:46: expected float but found {A with _time: B} (record) error @10:32-10:46: invalid binary operator <INVALID_OP> error @10:32-10:55: invalid binary operator <INVALID_OP>

I would appreciate your help… Maybe @Anaisdg could help?

Thanks!

@raymon

I recreated some test data using the same field names and tag names as yours, and I also got an error. The problem seems to be with the use of a tag name that gets confused to be an integer (maybe I am wrong about that, but it’s the only thing that seemed to cause the issues). So instead of using the tag names “20230130” and “20230222”, I used “Expiry20230130” and “Expiry20230222”.

See below:

import "influxdata/influxdb/schema"
from(bucket: "Options")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "dailyVols")
  |> filter(fn: (r) => r["_field"] == "vol")
  |> filter(fn: (r) => r["expiry"] == "Expiry20230130" or r["expiry"] == "Expiry20230222")
  |> filter(fn: (r) => r["SpotCode"] == "APPL")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> pivot(rowKey:["_time"], columnKey: ["expiry"], valueColumn: "_value")
  |> map(fn: (r) => ({ r with sumA: (r.Expiry20230130 + r.Expiry20230222) }))
  |> yield(name: "sum of two tag values")

aha, ic! Thx so much! :+1: :+1: :+1: