Table View difference from influx to grafana

Hi I got this query:

from(bucket: "chieam_new")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "tracker_alarms")
  |> group(columns: ["_field"])
  |> sort(columns: ["_time"])
  |> difference(columns: ["_value"], keepFirst: true)
  |> filter(fn: (r) => r._value != 0)
  |> map(fn: (r) => ({
    _time: r._time,
    _field: r._field,
    event: if r._value > 0 then "start" else "end"
  }))
  |> group(columns: ["_field"])
  |> pivot(rowKey: ["_field"], columnKey: ["event"], valueColumn: "_time")
  |> rename(columns: {start: "Event Start Time", end: "Event End Time"})
  |> sort(columns: ["Event Start Time"], desc: true)
  |> yield(name: "events")

That in influx displays correctly when a filed start to have a value ==1 and when this ends.

if i use the same query in Grafana with table-view i have a completely different view and i’m really puzzled in how to solve it as it only shows one event and not i the way i want to, any help is wellcome.

If you edit your panel and click Table view, what does it show?

Table View

Exactly the same

And you don’t have a dropdown box shown at the bottom of the table, right?

There is an empty dropdown list

I bumped into this problem. I went through far too many loops with AI tools to finally stumble on the answer, and I had to give it all manner of prompts to get there.

Both views illustrated are correct, but they are different ways of rendering the data supplied. I would guess that if a bit more of the InfluxDB screenshot was supplied (particularly above the table next to the search bar) we would see that these seven rows come from more than one table. I had a similar case: a six row resultset was labelled as 6 tables 6 rows (each table had one row).

What was happening in my case is that a group() function produces a table per group. I should think the same is happening here in the Grafana screenshots above, and the drop-down serves to choose between tables. (I suspect that the empty drop-down is just due to a missing _value or similar. That can be fixed, but it isn’t the headline here).

So to resolve this one has to unwrap or ungroup, and to do that one needs to do a group() with no parameters. So I think the functional approach is:

  • Do a group(columns: ["col1", "col2", "col3"...])
  • Do filtering, sorting, etc on the multi-table resultset
  • Ungroup using group() with no parameters, to create a single table

This works in the Simple Table rendering in InfluxDB (no change) and it will also work in the Table visualisation in Grafana (fixing the problem in the OP).

Hello @riodda

Just checking in—did this solution resolve your issue, or are you still experiencing the same problem?