How to sum some fields and display it in line chart?

I want to add a line chart displaying three lines: total_data (total_data_bytes), rx (rx_data_bytes), and tx (tx_data_bytes). I use this query below at first:

from(bucket: "wifi")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Client" and r["client_user_name"] =~ /^${userName:regex}$/)
  |> filter(fn: (r) => r._field == "total_data_bytes" or r._field == "rx_data_bytes" or r._field == "tx_data_bytes")
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> drop(columns:["_measurement"])

However, I noticed an issue with this chart where some lines appear identical.

This might be because users can connect to multiple Wi-Fi access points (APs). To address this, probably i have to consider summing the values for identical parameters. For example, if there are four rx_data_bytes lines, you could sum them into a single “Total Rx Data” line.

How to do that? Can someone tell me to build the query? Thank you so much!

Hello @alifyaza

from(bucket: "wifi")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Client")
  |> filter(fn: (r) => r["client_user_name"] =~ /^${userName:regex}$/)
  |> filter(fn: (r) => r._field == "total_data_bytes" or r._field == "rx_data_bytes" or r._field == "tx_data_bytes")
  |> group(columns: ["_time", "_field"])  // Group by time and field before summing
  |> aggregateWindow(every: 1m, fn: sum, createEmpty: false)
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> drop(columns:["_measurement"])

Try grouping by thing syou want to sum across :slight_smile: