Expression return null

hello,

I have this expression  :   IF($F{GENDER}=="Men",1,0)  the field is a string 

I have the option calculation on "sum"  and the value class name on "java.lang.Integer" , but every time i go preview it return me null

 

Can you help please

 

thank you

jbreuil's picture
Joined: Apr 11 2014 - 2:06am
Last seen: 8 years 7 months ago

1 Answer:

Instead of using the IF() function and assuming you are using Java as the language you could try:

$F{GENDER}.trim().equals("Men") ? 1 : 0

The IF() function will always return null when the argument is null.

To modify my suggestion to account for null values, you would need something like:

$F{GENDER} != null && $F{GENDER}.trim().equals("Men") ? 1 : 0 db

bolsover's picture
237
Joined: Aug 19 2009 - 1:35am
Last seen: 4 years 7 months ago
Feedback
randomness