Want to automate sql query in a bar graph

I would like to automate my bar graph. Currently I’m creating a new line for each unique entry to the database. Is there a way to do this with some kind of ‘SELECT DISTINCT’?

An example of the first line is;
CASE WHEN COUNT() FILTER(WHERE TestView.category = ‘python_test_assert’) > 0 THEN COUNT() FILTER(WHERE TestView.category = ‘python_test_assert’) ELSE null END AS python_test_assert,

In SQL if you group by unique key is same result than distinct function,
may you can work around with that :

i think you don’t need your case too

1 Like

I tried it, and it sort of worked. But now everything has the same color, as well as that the categories don’t show up in the legend;

nice ! perfect :slight_smile:
legend and color are panel options

Well, everything is marked as category_type. Is there an override to change color of bar based on value of category_type?

1 Like

yes ! maybe you can try first basic color option like “classic palette”,
if it’s not working you can make value mapping,
if still not try to do this with override to target the right column

I have tried all of them:/

you are right i can’t do it too…
It’s should work on label override of label column but it’s not .
I could do it through

1 Like

Ah, that’s a bit annoying though…
Thanks for trying atleast! Appreciate it!


1 Like

@yosiasz can you try to color that by name of series ? i can’t on 8.3 grafana

same here I can’t do it with Value mapping

I managed to get it working by setting the “Color by field” attribute