Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
L_VN
Partner - Contributor III
Partner - Contributor III

Why are booleans in Qlik -1 and 0 and not 1 and 0 like in most other languages?

Basically just the title. I don't at all see the point of it, and it causes issues when you multiply them (true * true != true), and also summing them returns a negative value. 

Please fill me in. 

Labels (1)
3 Replies
Chirantha
Support
Support

The reason for this is that -1 is equivalent to setting all the bits in the byte to 1, which is how TRUE is represented in most software systems (as opposed to FALSE, where all bits are set to 0). This is different from other languages where booleans are represented as 1 and 0. However, it is important to note that in situations where Qlik expects a Boolean, such as in the first parameter of the if() function or in a Where clause, Qlik will interpret 0 as FALSE, and all other numbers as TRUE. This means that a number of functions can be used as either Boolean or numeric functions, such as Index(), Match(), Substringcount(), and FieldIndex().

Please refer to the following posts below where other users have touched upon a similar question

Why is true represented by '-1'and not '1' in some... - Qlik Community - 1386348

On Boolean Fields and Functions - Qlik Community - 1462815

marcus_sommer

In each case where you want to use the flag as multiplicator or (range) summing it you could simply reverse the direction of the value by the flag-creation, like:

-(month(Date)=month(today())) as InMonthFlag

and you will get 0 or 1 as results.

L_VN
Partner - Contributor III
Partner - Contributor III
Author

Obviously there are ways around it, but I was asking why it was set up like it is