Using Flux yield() to differentiate between results from the same series

Hi all

I’m trying to work out a way to differentiate the results from different Flux queries when run as part of the same panel. Here’s the code:

import "date"
month = date.truncate(t: now(), unit: 1mo)

from(bucket: "Power")
  |> range(start: month)
  |> filter(fn: (r) => r["_measurement"] == "consumption")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["series"] == "House")
  |> filter(fn: (r) => r["_value"] > 0)
  |> sum()
  |> map(fn: (r) => ({ r with _value: r._value / 1000.0 * 0.1413 }))
  |> yield(name: "Consumed")

from(bucket: "Power")
  |> range(start: month)
  |> filter(fn: (r) => r["_measurement"] == "consumption")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["series"] == "Hot_Water")
  |> sum()
  |> map(fn: (r) => ({ r with _value: r._value / 1000.0 * 0.1283 }))
  |> yield(name: "Hot Water")

from(bucket: "Power")
  |> range(start: month)
  |> filter(fn: (r) => r["_measurement"] == "consumption")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["series"] == "House")
  |> filter(fn: (r) => r["_value"] < 0)
  |> sum()
  |> map(fn: (r) => ({ r with _value: r._value / 1000.0 * 0.49 }))
  |> yield(name: "Feed-In")

Both results from the House series end up labelled value House. The _result field that should be populated by the yield() function doesn’t appear to be presented to Grafana. When I run the same query in InfluxDB explorer, it seems to work.

Because the two House results have the same label, there is no way to differentiate them to override the display label.

Any ideas?

2 Likes

Hey @dan9bc6
Did you by now find a Solution for your Problem?
I have just the same issue.

@philipreutzel84 and @dan9bc6

I believe it is due to the way Grafana parses the result from InfluxDB. Try adding the following:

|> rename(columns: {_value: "something"})

@dan9bc6 I just found a solution.
For me, changing the output column in map() did it.
So instead of

you could use

|> map(fn: (r) => ({ r with Consumed: r._value / 1000.0 * 0.1413 }))

This I think adds a new column, so it´s maybe not the most performant way, but Grafana will actually show the new column and you can differentiate between the results.

1 Like