# Sort Bar Gauge by number column

**URL:** <https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073>\
**Category:** Bar Gauge Panel\
**Tags:** bar-gauge\
**Created:** [July 30, 2023, 3:24am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073 "2023-07-30T03:24:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexmondaini](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@alexmondaini](https://community.grafana.com/u/alexmondaini)\
**Post date:** [July 30, 2023, 3:24am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/1 "2023-07-30T03:24:23Z")

</div>

![day_tto.PNG](https://us1.discourse-cdn.com/grafana/original/3X/8/a/8a7a7b47c3b8c29e2cd5c25d8ce58693f2caad18.jpeg)  
I have a query like this with postgres as backend:

```auto
select distinct 
obsolete_date as time,
software_product_version_name as metric,
obsolete_date::date - current_date as days_to_expire
from evergreen
where current_date < obsolete_date
order by 1,3

```

How can i sort by days\_to\_expire ? So I have the earliest days on top of the graph, I tried the transformations but I cannot select that column in the SORT BY transformation

---

<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:** [July 30, 2023, 3:34am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/2 "2023-07-30T03:34:50Z")

</div>

not sure what you mean by earliest date but what if you just did

```auto
order by 3 desc

```

---

<div class="post-metadata">

**Author:** ![alexmondaini](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@alexmondaini](https://community.grafana.com/u/alexmondaini)\
**Post date:** [July 30, 2023, 4:17am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/3 "2023-07-30T04:17:42Z")

</div>

that doesn’t work, it is a time series type and i need to order by time too, I mean on the right side of the chart you can see many values as such: 52 days. I want them ordered from lowest number to highest number. The order now seems to be done by the way the columns appear in the underlying table from left to right, I would like to order the products by the number of days.

---

<div class="post-metadata">

**Author:** ![alexmondaini](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@alexmondaini](https://community.grafana.com/u/alexmondaini)\
**Post date:** [July 30, 2023, 4:18am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/4 "2023-07-30T04:18:22Z")

</div>

![tb_view](https://us1.discourse-cdn.com/grafana/original/3X/5/9/5912ac3bc81a0881407a62ed474923fddf6c7d2b.png)  
this is the table of the data

---

<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:** [July 30, 2023, 4:28am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/5 "2023-07-30T04:28:09Z")

</div>

How about add a transform to convert that columm to a number and the timw to time type them another transform to sort by the time field and the converted now numeric value

---

<div class="post-metadata">

**Author:** ![alexmondaini](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@alexmondaini](https://community.grafana.com/u/alexmondaini)\
**Post date:** [July 30, 2023, 4:40am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/6 "2023-07-30T04:40:11Z")

</div>

hi, in the first picture there is an alias called `days_to_expire` , that column is already an integer, not float. Do i need to make float ? the days you see there is just a modification in the standar options

 ![std_options](https://us1.discourse-cdn.com/grafana/original/3X/c/8/c84c6199c99f4afd747083e6fabd0cc422ce8d36.png)

---

<div class="post-metadata">

**Author:** ![alexmondaini](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@alexmondaini](https://community.grafana.com/u/alexmondaini)\
**Post date:** [July 30, 2023, 4:43am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/7 "2023-07-30T04:43:11Z")

</div>

furthemore, the field type `days_to_expire` does not even show in the transform values to choose, not sure why, for example if i start typing `days_to_expire` in the transform tab, nothing populates

 ![transff](https://us1.discourse-cdn.com/grafana/original/3X/b/f/bf996ada8bbd730c6d4e89d89161be46fbba0146.png)

---

<div class="post-metadata">

**Author:** ![alexmondaini](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@alexmondaini](https://community.grafana.com/u/alexmondaini)\
**Post date:** [July 30, 2023, 4:46am UTC](https://community.grafana.com/t/sort-bar-gauge-by-number-column/100073/8 "2023-07-30T04:46:52Z")

</div>

pic of the data types in the postgres backend, this is exactly how i want the order to be displayed in the gauge, but grafana is making this table a wide table, and the column days\_to\_expire becomes the values, so it doesn’t exist

 ![data types](https://us1.discourse-cdn.com/grafana/original/3X/d/e/de4e3152a026bf66f3509437ba011dffefe3b433.png)
