# Inconsistent sorting / order

**URL:** <https://community.grafana.com/t/inconsistent-sorting-order/136198>\
**Category:** Dashboards\
**Created:** [November 12, 2024, 10:30am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198 "2024-11-12T10:30:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eoin6](https://avatars.discourse-cdn.com/v4/letter/e/a587f6/32.png) [@eoin6](https://community.grafana.com/u/eoin6)\
**Post date:** [November 12, 2024, 10:30am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198/1 "2024-11-12T10:30:28Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 12, 2024, 10:52am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198/2 "2024-11-12T10:52:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eoin6](https://avatars.discourse-cdn.com/v4/letter/e/a587f6/32.png) [@eoin6](https://community.grafana.com/u/eoin6)\
**Post date:** [November 12, 2024, 11:11am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198/3 "2024-11-12T11:11:22Z")

</div>

**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:

```auto
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:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/1/8/1899bc34aa1d17d8e06c06cd7a3b06a58bedb1ca.png)

Custom Order Query:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/6/2/62ac1d042ed8f07dc4db65bd7af0484b2012a5d7.png)

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 12, 2024, 11:33am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198/4 "2024-11-12T11:33:36Z")

</div>

You have not specified any explicit sorting that I can see

---

<div class="post-metadata">

**Author:** ![eoin6](https://avatars.discourse-cdn.com/v4/letter/e/a587f6/32.png) [@eoin6](https://community.grafana.com/u/eoin6)\
**Post date:** [November 12, 2024, 11:35am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198/5 "2024-11-12T11:35:36Z")

</div>

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

> [@eoin6](#):
>
> ```auto
> |> 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
> })
> )
> 
> ```

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 12, 2024, 11:40am UTC](https://community.grafana.com/t/inconsistent-sorting-order/136198/6 "2024-11-12T11:40:41Z")

</div>

So that is sequence of columns

Sort is a whole different . meaning in the data world

But that said I see your issue
