# Subtract two variables

I have one variable:

BigDecimal

Calculation = Sum

Rest Type = report

Variable Expression = \$F{Potentials_Netto_Winst}

This variable gives me a sum of all the Potentials_Netto_Winst in the report..

Now I want to subtract that variable with another variable (also big decimal and initial value expression = 130000) and save the result in a 3rd variable..

How can I do that???

593
Joined: Nov 4 2011 - 6:41am
Last seen: 6 years 6 months ago

Try this, first, the two variable should both be BigDecimal, then set expression for the 3rd variable as \$V{v1}.subtract(\$V{v2})

438
Joined: Nov 26 2012 - 7:34pm
Last seen: 5 years 4 months ago

I did that:

Variable 3:

Variable Expression = \$V{Potentials_Netto_Winst}.subtract( \$V{Potentials_Totaal_Kosten_(â‚¬)_1} )

Result = null

593
Joined: Nov 4 2011 - 6:41am
Last seen: 6 years 6 months ago

I made a try, you should change the variable Potentials_Totaal_Kosten_(â‚¬)_1, set its property "Variable Expression", not the "Initial Value Expression", set to new BigDecimal(130000)

438
Joined: Nov 26 2012 - 7:34pm
Last seen: 5 years 4 months ago

I did that:
<variable name="VasteKost" class="java.math.BigDecimal">
<variableExpression>130000</variableExpression>
<initialValueExpression><![CDATA[]]></initialValueExpression>
</variable>
<variable name="variable1" class="java.math.BigDecimal">
<variableExpression><![CDATA[\$V{Potentials_Netto_Winst_(â‚¬)_2}.subtract( \$V{VasteKost} )]]></variableExpression>
</variable>

But now my Variable 'VasteKost' = null and my subtract result is also null

samhast - 10 years 1 month ago

When I add a variable and add the variable \$F{Potentials_Netto_Winst}
The restult = null.. But when i drag the variable \$F{Potentials_Netto_Winst} on my report i see the correct result.. So i don't know how I can subtract a value from a variable that is the sum of other values in the report..

samhast - 10 years 1 month ago

See Attachment. Is it possible to do calculation with such variable. Because this variable is already a sum of other fields...

When I do some calculations with fixed integers, it works. But everytime when I use the field you see in attachment, the result = null

Attachments:
AttachmentSize
10.97 KB
593
Joined: Nov 4 2011 - 6:41am
Last seen: 6 years 6 months ago

Solved --> evaluation time of my textfield = 'Now'. I changed it to Report.. Now it's ok..

samhast - 10 years 1 month ago

Sorry, it seems that I misled you. Please let me explain what I did,

first, create a variable named "Summary" do sum and it type as BigDecimal.

second, create a variable named "MinusValue" with Variable Expression "new BigDecimal(130000)"

third, create a variable named "ResultValue" with Variable Expression "\$V{Summary}.subtract(\$V{MinusValue})"

fourth, drag the variable Summary into report and set Evaluation Time of the field to "Report"

last, drag the variable ResultValue into report and set Evaluation Time of the field to "Report"

preview the report and that's all, hope this would help you.

438
Joined: Nov 26 2012 - 7:34pm
Last seen: 5 years 4 months ago
randomness