# New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
cancel
Showing results for
Did you mean:
Creator

## Color by expression in bar chart (if selected average > total average)

Hello.
I have a bar chart that displays the average courses ([Nome Evento]) an employee ([Nome do servidor]) has taken in a given period of time.

I want to color the dots based on whether the average of the selection is greater than the total average or not.
I tried this as an expression in the Colors and Legend tab:
if((Count({\$} distinct [Nome Evento]) /GetSelectedCount([Nome do servidor])) > (Count({1} distinct [Nome Evento]) / Count({1} [Nome do servidor])), ARGB(255,0,101,128), ARGB(255,135,32,93))

But it doesn't work. All the dots are always colored by a single color, as seen bellow:

How can I make it look like this:

But with the red color being only the values in which the average of selection is lower than the total average?

1 Solution

Accepted Solutions
Specialist II

Hi @lailarhc ,

if((Count({\$} distinct Curso) /GetSelectedCount([Nome do Servidor]))

>

(Count( total distinct Curso) / Count( total [Nome do Servidor])), ARGB(255,0,101,128), ARGB(255,135,32,93))

Note : At least more than 1 value to be selected for   [Nome do Servidor] field.

Regards,
Abhijit
keep Qliking...
6 Replies
Specialist II

Hi @lailarhc,

It's supposed to work.  Can you please share sample data??

Regards,
Abhijit
keep Qliking...
Partner - Champion II

try

if((Count({\$} distinct [Nome Evento]) /GetSelectedCount([Nome do servidor]))

>

(Count( total distinct [Nome Evento]) / Count( total [Nome do servidor])), ARGB(255,0,101,128), ARGB(255,135,32,93))

Creator
Author

Hello. I created a table with all the columns I'm using in my project, without any filters applies, and downloaded it as an excel file. Is that what you meant?

The file is attached.

Specialist II

Hi @lailarhc ,

I hope you are looking for the same as below.

Regards,
Abhijit
keep Qliking...
Creator
Author

Hello @abhijitnalekar , can you please post the expression you used to achieve this result? Thank you

Specialist II

Hi @lailarhc ,

if((Count({\$} distinct Curso) /GetSelectedCount([Nome do Servidor]))

>

(Count( total distinct Curso) / Count( total [Nome do Servidor])), ARGB(255,0,101,128), ARGB(255,135,32,93))

Note : At least more than 1 value to be selected for   [Nome do Servidor] field.

Regards,
Abhijit
keep Qliking...