Sortbby Field in a Table ends up like R1, R10, R11, R12, R2, R3,

  • What Grafana version and what operating system are you using?
    Grafana 11.1.0 on windows

  • What are you trying to achieve?
    Sort the field names in a table

  • How are you trying to achieve it?
    Click the name to sort it.

  • What happened?
    I have some variables labelled with xxx_R1, xxx_R2, xxx_R3, … xxx_R10, xxx_R11, xxx_R12 for max/min/last/mean in the field in a table dashboard.
    So far so fine.
    But when I click sortby Field, it will end up with xxx_R1, xxx_R10, xxx_R11, xxx_R12, xxx_R2, xxx_R3, …

  • What did you expect to happen?
    If I click sortby Field, it shall end up with xxx_R1, xxx_R2, xxx_R3, …, xxx_R10, xxx_R11, xxx_R12
    The only solution in my mind is to rename them. From xxx_R1, xxx_R2, xxx_R3, … to xxx_R01, xxx_R02, xxx_R03, …

Any better ideas?

Great thanks in advance

you could try use a regex to trim off the xxx_R part and then sort on it?

1 Like

So I tried, 1R, 2R, 3R, …, 10R, 11R, 12R and the result is the same

That’s expected. Labels in the legends are strings, so how are strings (which look like numbers) sorted?

What is your data source

When using the approach suggested by sowdenraymond, you should ensure the only thing left in the expression is the number (so you have to make sure that 1R is just 1), then you can use Grafana transformation Convert Field Type, where you convert the type of your field name to Number. Then sort by that field and that should work.

Thanks a lot for all your inputs.
I think that I will go for “01, 02, … etc” instead of “1,2,… etc”
Because eventually I would need R01_M01, R02_M01, …etc.