Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
bensomers
Contributor II
Contributor II

How to add colour to expression?

Hi experts,

Can anyone tell me how to adjust the below expression so that 'Pass' is green and 'Fail' is red?

=IF(Count({<SLAMet= {'Yes'}>} SLAMet)/Count(SLAMet)>.98,'Pass','Fail')

Thanks!

10 Replies
Vegar
MVP
MVP

Colour is set differently in the different object types, but if you know where to put the colour expression then you could use this:

IF(Count({<SLAMet= {'Yes'}>} SLAMet)/Count(SLAMet)>.98,green(),red())

 

bensomers
Contributor II
Contributor II
Author

Hi Vegar,

I have tried using KPI and Text & Image but this doesn't seem to work.

Thanks for you post though.

Nesma_Aldash
Contributor
Contributor

To introduce colors, you need to get their number.

The shade of green I chose was #cbe989, and the red i chose was #ff919b. You can get the numbers by going to the colors tab in Appearance (image attached).

If you're applying this to a table, you can add the below formula. Just replace "Name" with the dimension/measure name. The formula can go in "Background Color Expression" or "Text Color Expression" (Image 2):

if(Name= 'Pass', '#cbe989', '#f9ec86')

Hope this helps.

bensomers
Contributor II
Contributor II
Author

Thanks, Nesma_Aldash! That's some really helpful info. Unfortunately as I'm trying to display a very simple, large font "Pass" or "Fail" the table option doesn't quite work.

Currently I am using the KPI option and everything works except being able to colour the "Pass" or "Fail" - There is no 'Color Expression' option in KPI, so I was hoping to be able to include the colour prompt within the expression I am already using:

=IF(Count({<SLAMet= {'Yes'}>} SLAMet)/Count(SLAMet)>.98,'Pass','Fail')

Unless you can recommend an object other than KPI that may be appropriate?

Vegar
MVP
MVP

Assuming that your color is based on your KPI  expression, Count({<SLAMet= {'Yes'}>} SLAMet)/Count(SLAMet), then you can set your colors and the limit where to change color inside the color  properties pane (Sorry for the Swedish language in the picture below)

image.png

bensomers
Contributor II
Contributor II
Author

Thanks, Vegar. The expression I am using is:

=IF(Count({<SLAMet= {'Yes'}>} SLAMet)/Count(SLAMet)>.98,'Pass','Fail')

When I go to the color section and turn conditional colors on and library off it displays an error "unable to change the properties because there is an error in the expression".

dwforest
Specialist II
Specialist II

You don't put the formula for the KPI limit color, just the limit, in your case. .98

Then in the bar above, set the color by clicking it left and right of the .98 line created with the red/green colors you want

Vegar
MVP
MVP

Good morning.

@dwforest the issue here is that the value of the kpi is not numeric, it is
'Pass' or 'Fail'. A threshold on 0.95 won't work and it is not possible to
enter threshold limits in a KPI when the output is text.

I've tried to create an dual output, but the KPI then choose to present the
numerical representation of the dual.

I'm starting to believe that the styling @bensomers want to do is not
possible. An alternative approach would be to create a KPI lookalike using
a text object. I think the text object is a bit more flexible in its
styling capabilities.

—Vegar
Sameer9585
Creator II
Creator II

Hi @bensomers ,

The please follow these steps.

Create a dimension and give in the expression as =IF(Count({<SLAMet= {'Yes'}>} SLAMet)/Count(SLAMet)>.98,'Pass','Fail') and name it as Flag

then if you extend that dimension you find 'Background Color Expression' and in that give like this

pick(match(Flag,Pass,Fail),rgb(0,255,0),rgb(255,0,0)).

May this helps