Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Changing the colour of a single bar in a bar chart

Hi all,

What I thought would be quite simple is turing out to be trickier than expected and wondered if anyone could help

I have a bar graph which work perfectly well and on the caption of the bar graph i've got it to display the average for the data

'Average Age =' & Round(avg({$< comp_anal.EcStatus = {'Registered'} >}comp_anal.Comp_Age),1)

What i'm now trying to do is turn the bar which pertains to the average a different colour

If I use the background setting on the expression of the chart and set this to an actual value it works fine

=if (comp_anal.Comp_Age =

50

,  RGB(64,0,128),RGB (141,170,203))

however

if i now substitute that with the equation im using for the average it turns every bar into the 'yes' value

=if (comp_anal.Comp_Age =

Round(avg({$< comp_anal.EcStatus = {'Registered'}>}comp_anal.Comp_Age),1)

,  RGB(64,0,128),RGB (141,170,203))

can anyone recommend anything?

Many thanks

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I guess the avg is calculated for each bar here, hence the condition is true for each.  Try adding total:
=if (comp_anal.Comp_Age =

Round(avg(total {$< comp_anal.EcStatus = {'Registered'}>}comp_anal.Comp_Age),1)

,  RGB(64,0,128),RGB (141,170,203))

If it doesn't help - upload an example.

View solution in original post

3 Replies
Anonymous
Not applicable
Author

I guess the avg is calculated for each bar here, hence the condition is true for each.  Try adding total:
=if (comp_anal.Comp_Age =

Round(avg(total {$< comp_anal.EcStatus = {'Registered'}>}comp_anal.Comp_Age),1)

,  RGB(64,0,128),RGB (141,170,203))

If it doesn't help - upload an example.

Anonymous
Not applicable
Author

you can use variable

var1=Round(sum(if (comp_anal.EcStatus = "Registered",comp_anal.Comp_Age,0))/count(if (comp_anal.EcStatus = "Registered",comp_anal.Comp_Age)))

and the use this variable in expression

PS: check the brackets syntax

Thanks

BKC

Not applicable
Author

thanks Michael

I'm sure Balks worked as well, but Michaels was easier to implement