Grouping data by fields

Hi,

I am have 2 different measurements with few columns that are same. This is default query for both measurements showing the same columns

from(bucket: "bucket1")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement1" or r["_measurement"] == "measurement2")
  |> filter(fn: (r) => r["_field"] == "field1" or r["_field"] == "field2")
  |> filter(fn: (r) => r["tag1"] == "1")
  |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Resulting in
image

I am trying to aggregate and group data by column but I am not sure how to do that correctly because if I group by value all the columns get grouped into one. Here is what I am trying:

from(bucket: "bucket1")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement1" or r["_measurement"] == "measurement2")
  |> filter(fn: (r) => r["_field"] == "field1" or r["_field"] == "field2")
  |> filter(fn: (r) => r["tag1"] == "1")
  |> group(columns: ["_time"])
  |> mean(column: "_value")
  |> group()
  |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
  |> yield(name: "mean")

But what I get is then one graph instead of two

What I need is to group somehow by fields but I am failing to do so.

@maholi Does this accomplish what you’re trying to do?

from(bucket: "bucket1")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement1" or r["_measurement"] == "measurement2")
  |> filter(fn: (r) => r["_field"] == "field1" or r["_field"] == "field2")
  |> filter(fn: (r) => r["tag1"] == "1")
  |> group(columns: ["_field"])
  |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Yes, thank you, it seems like that is the solution. Although we ended up with a different approach of dropping a column measurement since we might have more than 2 in the future and it should still work like that. Also, the query seems to execute faster in dropping measurement way.