Multiple if conditions within variable expression

0

 

I need the syntax for a formula with in a variable expression that tests for two main condtions and each main condition has sub condtions.

//  if sold_to = 'Partner 1' then
//    if ((qs = 0) or (qd = 0) or ((100 * qs / qd) > 100)) then 0 else (100 * qs / qd)
//  else if sold_to = 'Partner 2' then
//    if ((qs = 0) and (kw = 0)) then category value
//  else if (kw = 0) then 0 else (qs / kw * 100)

below code assigns 100 if not partner 1 or 2 instead of testing if KW = 0

Code:
$F{SOLD_TO}.equals("Partner 1")
  ? ($V{EofW_QS}.floatValue() == 0 || $V{EofW_QD}.floatValue() == 0 || (100*$V{EofW_QS}.floatValue())/$V{EofW_QD}.floatValue() > 100) 
    ? new Double(100) : new Double(100.0*$V{EofW_QS}.floatValue()/$V{EofW_QD}.floatValue())
: 
  $F{SOLD_TO}.equals("Partner 2") 
    ? ($V{EofW_QS}.floatValue() == 0 && $V{EofW_QW}.floatValue() == 0) ? new Double(100)	
:  
  $V{EofW_KW}.floatValue()==0
    ? new Double(0) : new Double($V{EofW_QS}.floatValue() / $V{EofW_KW}.floatValue() * 100)
:     
 new Double(100)</td></tr></tbody></table>
dcodling's picture
Joined: Apr 12 2010 - 3:18pm
Last seen: 8 years 11 months ago

1 Answer:

2

The base syntax is:

(condition) ? (exp on true) : (exp on false)

exp on true or false can be another similar expression.

I.e:

($F{Col} == 1) ? "red" :  ( 
    ($F{Col} == 2) ? "green" : (
          ($F{Col} == 3) ? "blue" :  "white"
            )
   )

Pay attention to the parenthesis...

Giulio



Post Edited by giulio at 04/12/2010 23:35
giulio's picture
18886
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 month 1 week ago
Feedback
randomness