Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
sayadutt
Creator
Creator

Help required in simple if-else condition

Hi All,

My requirement is to colour the backgroud (bakground colour) for a particular chart.

My requirement is to colour it

blue if Practice Area = AAA and vReqDateVar <= 2

red if Practice Area = BBB and vReqDateVar <= 3

for rest its green.

For that I am using below expression in Background colour in expression.

if([Practice Area  ] = 'AAA' and vReqDateVar <= 2, blue(),

if([Practice Area  ] = 'BBB' and vReqDateVar <= 3, red(), green()))

But it always returns Green.

Can you please tell me what I did wrong. I am new to qlikview.

Thanks

1 Solution

Accepted Solutions
Colin-Albert

Add a dummy expression  =1 so you can see all values

or set the Presentation sheet so Missing and Zero Values are not suppressed

View solution in original post

8 Replies
Colin-Albert

I would add a test Straight table chart with  Practice Area and vReqDateVar as dimensions and add this version of your background formula as the expression.

     if([Practice Area  ] = 'AAA' and vReqDateVar <= 2, 'blue',

          if([Practice Area  ] = 'BBB' and vReqDateVar <= 3, 'red', 'green')

You should then be able to see the values for the data and the result.

sayadutt
Creator
Creator
Author

Hi Albert,

vReqDateVar is a variable which is calculating difference in 2 dates.

my vReqDateVar is defined as = Date#([Requirements Actual Date  ]) - Date#([Requirements Planned Date  ])

It returns numbers.


I tried your above code, but does not return any color. (I also added 1 missing paranthesis at the end)


Can you please suggest.

nagaiank
Specialist III
Specialist III

Did you try using [Practice Area]  instead of [Practice Area  ]  ?

sayadutt
Creator
Creator
Author

Yes, thats not the issue. Other graphs work with [Practice Area  ] .

I guess the issue is with else part. My code always going to else part and printing green.

if([Practice Area  ] = 'AAA' and vReqDateVar <= 2, blue(),

if([Practice Area  ] = 'BBB' and vReqDateVar <= 3, red(), green()))

Colin-Albert

Add a dummy expression  =1 so you can see all values

or set the Presentation sheet so Missing and Zero Values are not suppressed

Not applicable

Hi,

I added the following to one of my charts & it worked fine...

If([CONTACT DIRECTORATE] = 'CANCER' And Count([CONTACT DIRECTORATE]) >0,

//Then

  blue(),

//Else If

  If([CONTACT DIRECTORATE] = 'PATHOL' And Count([CONTACT DIRECTORATE]) >0,

//Then

  red(),

//Else

  green()))

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

What is the content of your variable vReqDateVar - does this just contain a value, or is it an expression?


If it is an expression then you may need to dollar sign expand it, eg. $(vReqDateVar).


The space in your field name looks odd, I would try removing that.


Test things by adding [Practice Area] as a dimension, and vReqDateVar as an expression, this way you can see what values are being used.  You can also replace the colours in your colour expression with integers and have that as an expression.  You can then see if you get the right values out of the if statement.


Additional: Sorry, just seen your response earlier, I strongly suspect it is the $(vReqDateVar) syntax you need.

Steve

nithin_miryala
Creator
Creator

Hi Sayantan,

If you can add the application it will be more clear. because your expression is correct.

Thanks Nithin