Table in flux with function in only one column

I have this query in influxDB that works fine, shows me all the three columns, but when I copy and paste to grafana, it only shows me the points column.
Also both in influx and grafana it generates me one table for each pilot, when they should actually be on the same table.
Any ideias how to fix that up?

from(bucket: “test”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “test”)
|> filter(fn: (r) => r[“team”] == “Usual Racing”)
|> filter(fn: (r) => r[“Lap”] == “2”)
|> filter(fn: (r) => r[“_field”] == “trigger” or r[“_tag”] == “Lap”)
|> group(columns: [“Pilot_name”, “Lap”])
|> sum()
|> rename(columns: {_value: “Points”})
|> keep(columns: [“Points”, “Pilot_name”, “Lap”])

I’m not 100% sure, but this sounds like Grafana is not displaying the columns in the group key. Depending on the visualization type you’re using, there may be a setting that changes this behavior.

In the Flux data model, each individual “group” is represented by a table. So by grouping your data by Pilot_name and Lap, you’re going to have an individual table for each unique combination of those tags. To group them into a single table, you can “ungroup” your data after you calculate the sum:

from(bucket: "test")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "test")
    |> filter(fn: (r) => r["team"] == "Usual Racing")
    |> filter(fn: (r) => r["Lap"] == "2")
    |> filter(fn: (r) => r["_field"] == "trigger" or r["_tag"] == "Lap")
    |> group(columns: ["Pilot_name", "Lap"])
    |> sum()
    |> group()
    |> rename(columns: {_value: "Points"})
    |> keep(columns: ["Points", "Pilot_name", "Lap"])
1 Like

It worked perfectly Scott, thank you!! Only the columns order that is not right, even changing it on the keep() still doens’t alter.

Unfortunately Flux doesn’t let you specify column order. You’d have to do this client-side.