BIRT Conditional aggregate in an expression

Options
mxenakis
edited February 11, 2022 in Analytics #1
<p>Hi -</p>
<p> </p>
<p>I'm new to BIRT and I'm trying to build an aggrigate based on a condition.  I've got the following Fields:</p>
<p> </p>
<p>PLAN1</p>
<p>PLAN1_VALUE</p>
<p>PLAN2</p>
<p>PLAN2_VALUE</p>
<p>PLAN3</p>
<p>PLAN3_VALUE</p>
<p> </p>
<p>I need to write a condition as follows:</p>
<p> </p>
<p>If PLAN1 = 'SALES' then PLAN1_VALUE ELSE 0 END IF;</p>
<p>+</p>
<p>If PLAN2 = 'SALES' then PLAN2_VALUE ELSE 0 END IF;</p>
<p>+</p>
<p>If PLAN3 = 'SALES' then PLAN3_VALUE ELSE 0 END IF;</p>
<p>+</p>
<p>If PLAN4 = 'SALES' then PLAN4_VALUE ELSE 0 END IF;</p>
<p> </p>
<p>I'm getting an error when trying to write the expression.  I'm new to javascript :)</p>
<p>I can get the one condition to work, but I'm running into a problem with adding them together.</p>
<p> </p>
<p><b>if</b> (dataSetRow["PLAN1"] = 'Sales' ){</p>
<p>dataSetRow["PLAN1_VALUE"];</p>
<p>}</p>
<p><b>else</b> {</p>
<p>0;</p>
<p>}</p>
<p>+</p>
<p><b>if</b> (dataSetRow["PLAN12] = 'Sales' ){</p>
<p>dataSetRow["PLAN2_VALUE"];</p>
<p>}</p>
<p><b>else</b> {</p>
<p>0;</p>
<p>}</p>
<p> </p>
<p>You're help would be greatly appreciated!</p>
<p>+</p>
<p><b>if</b> (dataSetRow["PLAN3"] = 'Sales' ){</p>
<p>dataSetRow["PLAN3_VALUE"];</p>
<p>}</p>
<p><b>else</b> {</p>
<p>0;</p>
<p>}</p>

Comments

  • <p>If you copied/pasted your javascript, there's an error in your PLAN2 section:</p>
    <pre class="_prettyXprint">
    if (dataSetRow["PLAN12] = 'Sales' ){
    </pre>
    <p>I'm guessing you wanted that to say:</p>
    <pre class="_prettyXprint _lang-">
    if (dataSetRow["PLAN2] = 'Sales' ){
    </pre>