Influxdb, flux query, bucket contains 2 string columns, how to get average of count of columns

112 views Asked by At

I have a bucket with multiple tags, measurements and fields. Mostly fields contains string values. Example, car country manufacturer gearboxtype etc. I want to take average in such way: What is the average of unique manufacturers per country. ( count of total manufacturers{which are names} to count to total unique country{which are names}).

Please note that, after unique() and count() only 2 columns are left "table _result" and "_value"

For this I tried to count both manufacturers and country, and have stored it in a variable, but when I try to divide both the variables it doesn't work.

var1= from(bucket: "cars")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "manufacturer")
  |> filter(fn: (r) => r["_field"] == "Name")
  |> unique()
  |> group()
  |> count()
  |> toInt()

var2=from(bucket: "cars")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "country")
    |> filter(fn: (r) => r["_field"] == "name")
  |> group(columns: ["name"])
 |> distinct(column: "name")
  |> group()
 |> count()
 |> toInt()

  var3 = var2/var1

  Error it gives: stream[{A with _value: B, _value: int}] is not Divisible
0

There are 0 answers