Rename double field

Hi all!
I have these 2 query:

from(bucket: “Internet_connections”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “Megabytes”)
|> filter(fn: (r) => r[“SIM”] == “Giulietta”)
|> filter(fn: (r) => r[“_field”] == “MB_residui”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)

from(bucket: “Internet_connections”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “Megabytes”)
|> filter(fn: (r) => r[“SIM”] == “Giulietta”)
|> filter(fn: (r) => r[“_field”] == “MB_residui”)
|> aggregateWindow(every: 1m, fn: last)
|> fill(usePrevious: true) // optional, depends on what you want
|> difference(columns: [“_value”])

The first one gives me the total amount of available data and the second one gives me the amount of data used in 1 day, BUT they both give me the same label name. When I have to change a label usually I use an override rule and change the display name, but since they have the same name, how do I do that?
Thanks!

Hi @pereus,
I found two solutions so pick one that suits you better.

Grafana: Use override Fields returned by query

Separate your queries into two different queries (A & B) under panel. Apply override Fields returned by query, select query that you want to rename (e.g. A) and Add override property Standard options > Display name. Repeat for query B. Be aware that your queries (i.e. A, B) should return only one series because Fiedls returned by query will apply specified name to all series that come from that query.

 

InfluxDB: Use rename function

Apply rename function to you queries. Before using rename function I dropped all other columns with keep() so that I would get clean legend text (without tags) but you can keep tags that you need.

This approach might be better if you want to perform different functions (e.g. mean, max, math operations…) on your data. Instead of querying data once for every function you can query once and save it to variable and then perform different functions. This results in more optimized query. At the end you can just rename fields to differentiate them on graph. However, I don’t think that you will have issues with performance so this approach might be redundant in this case.

 

Best regards,
ldrascic

1 Like

Wow, tanks a lot!!!
In the meanwhile I’ve discovered that the second query is wrong, it should graph the data used every day based on the total counter, but…

Do you know what can be wrong?