Inconsistent sorting / order

I’m experiencing an inconsistent behavior with data formatting in Grafana when using a custom column order in my Flux query. I hope someone can shed some light on this issue.

My query looks like this:

from(bucket: "data")
  |> range(start: -21d)
  |> filter(fn: (r) => r._measurement == "co2SensorData" and r.co2DeviceName == "${co2DeviceName}")
  |> filter(fn: (r) => r._field == "temperature" or r._field == "humidity" or r._field == "light" or r._field == "co2" or r._field == "voc" or r._field == "vdd" or r._field == "motion")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({
      _time: r._time,
      co2DeviceName: r.co2DeviceName,
      temperature: r.temperature,
      humidity: r.humidity,
      light: r.light,
      co2: r.co2,
      voc: r.voc,
      vdd: r.vdd,
      motion: r.motion
    })
  )
  |> yield(name: "results")

The issue I’m facing is that when I use this query to specify a custom column order, Grafana inconsistently formats my data. However, when I don’t specify an order and use the default query, the formatting remains consistent.

Thank you in advance for your help!

Please specify order of what exactly in Grafana is a problem. How it is query formatted,… Generally, provide reproducible example. There can be many variables in your case (e. g. Grafana version) and you specified none of them.

1 Like

What Grafana version and what operating system are you using?
10.4

What are you trying to achieve?
Using the Stat panel (in a repeating row by variable ${vocDeviceName}, I wanted to change the order in which the data is displayed from the Grafana default order.

How are you trying to achieve it?
Using this query:

from(bucket: "data")
  |> range(start: -21d)
  |> filter(fn: (r) => r._measurement == "co2SensorData" and r.co2DeviceName == "${co2DeviceName}")
  |> filter(fn: (r) => r._field == "temperature" or r._field == "humidity" or r._field == "light" or r._field == "co2" or r._field == "voc" or r._field == "vdd" or r._field == "motion")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({
      _time: r._time,
      co2DeviceName: r.co2DeviceName,
      temperature: r.temperature,
      humidity: r.humidity,
      light: r.light,
      co2: r.co2,
      voc: r.voc,
      vdd: r.vdd,
      motion: r.motion
    })
  )
  |> yield(name: "results")

What happened?
Upon trying multiple other types of queries including this one, each time the page is refreshed and a repeating panel is rendered, the order is completely different each time.

What did you expect to happen?
I expected the data in the panels to return the mapped sorted order from the query.

Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
No, the query executed fine.

Screenshot to help visualize
Default Grafana Order:

Custom Order Query:

You have not specified any explicit sorting that I can see

Is this not explicitly sorting the data? Returning a mapped of the results in the order I want.

So that is sequence of columns

Sort is a whole different . meaning in the data world

But that said I see your issue