Hello everyone, This might be a beginner-level question, but I just haven’t been able to figure it out. I’m sharing the query I wrote for InfluxDB and its output in the visual. I want to sum all the values and add that total next to each operation. How can I do this?
Expected outpup:
Regards,
you can consider this solution to reslolve your issue
Step 1. Create Bucket
Step 2. line protocol format for dummy data
weather,sensor=s1 temperature=20,humidity=40
weather,sensor=s1 temperature=21,humidity=42
weather,sensor=s1 temperature=22,humidity=43
weather,sensor=s1 temperature=23,humidity=45
Step 3. Integrate influxdb with grafana dashboard
Step 4.write the quert to find the total and show in different colum
// Step 1: Get pivoted weather data for humidity and temperature
data = from(bucket: "Dataabsolute")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "weather" and
r.sensor == "s1" and
(r._field == "temperature" or r._field == "humidity")
)
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
// Step 2: Calculate the total humidity over the range and assign dummy join key
humiditySum = from(bucket: "Dataabsolute")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "weather" and
r.sensor == "s1" and
r._field == "humidity"
)
|> sum(column: "_value")
|> map(fn: (r) => ({join_key: "1", humidity_sum: r._value}))
// Step 3: Add dummy join key to pivoted data
dataWithKey = data
|> map(fn: (r) => ({r with join_key: "1"}))
// Step 4: Join on dummy key to get humidity_sum into every row
join(
tables: {d: dataWithKey, s: humiditySum},
on: ["join_key"]
)
|> map(fn: (r) => ({
_time: r._time,
humidity: r.humidity,
humidity_sum: r.humidity_sum
}))
Final output Look Like this
Hello @ataliponder,
Just checking in—did this solution resolve your issue, or are you still experiencing the same problem?
Thank you for your efforts. However, I couldn’t implement the query you wrote to my data.
from(bucket: “bucket123”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“KANALKOD”] =~ /^06/ and r[“KANALKOD”] != “060501” and r[“KANALKOD”] != “060502” and r[“KANALKOD”] != “060503”)
|> filter(fn: (r) => r[“_field”] == “ADET”)
|> group(columns: [“OPERATIONCODE”], mode: “by”)
|> sum(column: “_value”)
|> keep(columns: [“OPERATIONCODE”,“_value”])
|> group()
This is my only query and result above.