1

Grafana 7.5.1 with InfluxDB 1.8.2. I'm trying to create a table that displays a sum of the "units" values for each distinct tag value. I am getting the data, but I need the sums to be sorted in descending order by default. This is my Flux query:

    from(bucket: "consumption") 
    |> range(start: -1y) 
    |> filter(fn: (r)  => r._measurement == "stuff" and r._field == "units" and r._value > 0) 
    |> group(columns: ["dc","tnt"]) 
    |> sum(column: "_value")
    |> sort(columns: ["_value"], desc: true)
    |> map(fn: (r) => ({r with _value: r._value / 4.0}))
    |> yield()

I also have a Reduce transformation (Calculations --> Total) and Organize Fields transformation.

But no matter what I do in the sort function, it doesn't change anything in the table. The table is just always sorted alphabetically by the tag values ("dc", "tnt"). I need it to be sorted by _value descending. What am I doing wrong?

Thanks!

Shana
  • 71
  • 2
  • 7
  • FYI I was able to get around this issue by manually sorting the column descending in the visualization and then saving it like that, but I still don't understand why the sort function is not having any effect. – Shana Sep 22 '20 at 23:19
  • I'm running into the same issue. It's related to the group() function as it produces a table per "dc", "tnt" combination. And the sort works on each of those tables. I'm desperately looking for the function to combine everything into a single table. – Peter Donker Apr 21 '21 at 09:17

1 Answers1

5

This video explains what you're seeing:

https://www.youtube.com/watch?v=9B4ioIlNGMk

Basically you'll need to add an empty |> group() before your sort to collapse all those tables into one.

Peter Donker
  • 328
  • 2
  • 15