Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Convert boolean to integer

Hi everyone,
I need to do diverse calculation with a column which contain boolean value, but PowerBI isn't understanding boolean as integer.
I want to add a new column in my dimension, with the integer of this boolean value but my expression is always returning 0 even for un true boolean :
lookup1.Column1.equals("1")?1:0 
(Column1 is a boolean)
Does anyone know where is my mistake, or how can I do it ?
Thank's in advance,
Julien
Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II

Hi,
If the datatype of lookup1.Column1 is boolean, you should write
lookup1.Column1 ? 1 : 0

Regards,
TRF

View solution in original post

5 Replies
TRF
Champion II

Hi,
If the datatype of lookup1.Column1 is boolean, you should write
lookup1.Column1 ? 1 : 0

Regards,
TRF
Anonymous
Not applicable
Author

Hi,
Thank's a lot
It does work, but can you just explain me why please ? I'm a Java novice and I'd like to understand.
Thank's in advance,
Julien
Anonymous
Not applicable
Author

It's a Java ternary operator and is equivalent to: -
if(lookup1.Column1) 1; else 0;
but you can't easily use an if statement in a mapping expression.
If you mean, why does you way not work, take a look at the Java help for Boolean.equal()
TRF
Champion II

That's it!
Anonymous
Not applicable
Author

Thank's a lot to both of you !!