Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort the bar chart considering the category in Google Data Studio?

I have been trying to change the order of the bar chart, so that the values for "Positiva" would appear first, then followed by "Negativa" and "Não sei". After reading some information on Google Data Studio forum, I saw that I should create a formula and then add it to the sort option. But it still didn't work.

The image below shows my bar chart. The category in green should come at first, followed by red and gray. I don't want to change the colors, I want to change the order.

enter image description here

So, after reading the forum, I created this formula and added to sort option, but I got an error. How can I solve it? And is there a way to centralize the percentage? enter image description here

like image 256
polo Avatar asked Jan 17 '26 08:01

polo


1 Answers

It can be achieved by using the Calculated Field below as the Secondary Sort, and setting the Order to Descending:

AVG(CASE
    WHEN REGEXP_MATCH(answer, "(?i)(Positiva)") THEN 3
    WHEN REGEXP_MATCH(answer, "(?i)(Negativa)") THEN 2
    WHEN REGEXP_MATCH(answer, "(?i)(Não sei)") THEN 1
    ELSE 0 END)

Google Data Studio Report and a GIF to elaborate:

like image 128
Nimantha Avatar answered Jan 20 '26 11:01

Nimantha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!