Multiple value on same row table view influxdb 2

hello all ,
i’m new with influxdb flux query , i’m looking to display list of interfaces information ( If name , If speed , if status , etc ) on the same table view fow and i’m already made a query but i got all that values on same column which i want that different values on separate columns on same row regarding name of interfaces , really appreciate your support .

example of query

from(bucket: "snmp")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "interface")
  |> filter(fn: (r) => r["_field"] == "ifOperStatus" or r["_field"] == "ifSpeed" or r["_field"] == "ifAdminStatus")
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> group(columns: ["ifName"] )
  |> keep(columns: ["_field","_value","ifDescr"])

table example i’m looking for looks like

table i got from query

regards

I think i made it by using pivot(), kindly if you have more suggestion please advice

here example from my query

from(bucket: "ltt")
|> range(start: -10m )
  |> filter(fn: (r) => r["_measurement"] == "interface")
  |> filter(fn: (r) => r["_field"] == "ifSpeed" or r["_field"] == "ifOperStatus" or r["_field"] == "ifAdminStatus" or r["_field"] == "ifMtu")
  |> filter(fn: (r) => r["agent_host"] == "192.168.4.33")
    |> aggregateWindow(every: 10m , fn: last, createEmpty: false)
  |> pivot(
    rowKey:["_time"],
    columnKey: ["_field"],
    valueColumn: "_value"
  ) 
  |> group(columns: ["ifName"] )
  |> keep(columns: ["ifDescr" ,"ifSpeed","ifOperStatus","ifAdminStatus","ifMtu"])
  |> rename(columns: {ifOperStatus: "OpStatus", ifSpeed: "Speed" , ifAdminStatus: "Admin Status", ifMtu:"MTU"})
  |> yield(name:"last")

1 Like

@legopixel,
You can also use fieldsAsCol() here which is a just a pivot function for precisely that type of pivot
https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/schema/fieldsascols/