# IF ELSE-IF ELSE-IF ELSE END IF / Switch Help please

## Recommended Posts

Im new to jaspersoft world and trying to write an expresion that evaluates the value of a text box

IF
CP =1 AND TP = 1 Then "CT"
ELSEIF
CP =1 THEN "C"
ELSEIF
TP = 1 THEN "T"
ELSE
""
END IF

I tried the following with not much success

IF (\$F{CP} == 11 && \$F{TP} == 1),"CT", IF (\$F{CP} == 1),"C",IF (\$F{TP} == 1),"T",""

This works partially but it doesnt evalue the expression in the else part and expects a constant...and not one more expression to evaluate

((\$F{CP} == 1)  &&  (\$F{TP})== 1) ? "CT" : (\$F{CP} == 1)? "C" : (\$F{TP} == 1)? "T"

Any tips on writing expressions would help greatly...even if its your own cheatsheet?

• Replies 3
• Created

#### Popular Days

It seems that you forgot the last ELSE expression( : "")

Here's how I would write it(aimed more at readability, you don't have to use parenthesis at all):

(\$F{CP} == 1  &&  \$F{TP} == 1) ? "CT" : (\$F{CP} == 1 ? "C" : (\$F{TP} == 1 ? "T" : ""))

##### Share on other sites

Thank you!

I figured out soon after my original post...;) Here it is for the benefit of others

(\$F{CP} == 1  && \$F{TP}==11) ? "XT":
\$F{CP} == 1 ? "X":
\$F{TP}== 1 ? "T":""

Here's another example

\$F{P} == 1 ? "1  -  10-19%":
\$F{P} == 2 ? "2  -  20-39%":
\$F{P} == 3 ? "3  -  40-59%":
\$F{P} == 4 ? "4  -  60-79%":
\$F{P} == 5 ? "5  -  80-100%":
""

Hope that helps!

##### Share on other sites

• 5 years later...

This topic helped me, thank you for sharing!