Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Boolean variables and conditional expressions

Hello fellows,

I would like to write the following expression (pseudo-code):

// define boolean variable

let variable = true;

// check if boolean variable is true

if (true) then

     // some code goes here

then

     // other code

end if

QV's behavior seems to be totally cont-intuitive here, i.e. it doesn't properly check if (true) condition. SO far I've tried

- if ($(variable))

- if ($(variable) = True)

- if ($(variable) = true() )

- ...

Can someone explain how to work with boolean variables and conditional expressions?

1 Solution

Accepted Solutions
6 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

True() is a function returning true (-1):

let variable = true();


and then

If($(variable), <true expr>, <false expr>)


HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
tresesco
MVP
MVP

If <Condition> Then ....

for your case, you can try like:

Let variable=1;

If $(variable)=1 Then ...

OR

Set  variable='true';

If $(variable)='true' Then ...

jonathandienst
Partner - Champion III
Partner - Champion III

And also:

    

     let variable = true();

     If variable Then

     ... script code ...

     Else     

     ... script code

     End If

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
maxgro
MVP
MVP

Not applicable
Author

That's indeed a good article!

The problem behind was QV's way to treat variables in 'dual' form. Correct way to check a boolean value within a if expression would be either

if (variable = 'True') (note capital letter!)

or

if (variable <> 0)

Anonymous
Not applicable
Author

Let vMyVariable = True();

If '$(vMyVariable)' = 'True' Then

     // business logic here

End If

// likewise, use False() and 'False'