[resolved] Convert boolean to integer

One Star

[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

Accepted Solutions
One Star

Re: [resolved] Convert boolean to integer

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

Regards,
TRF

All Replies
One Star

Re: [resolved] Convert boolean to integer

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

Regards,
TRF
One Star

Re: [resolved] Convert boolean to integer

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
Five Stars

Re: [resolved] Convert boolean to integer

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()
One Star

Re: [resolved] Convert boolean to integer

That's it!
One Star

Re: [resolved] Convert boolean to integer

Thank's a lot to both of you !!