Search code examples
jasper-reports

In Studio is there any way to subtract from a "global" variable?


In my case, I have one variable that is $V{TotalHours} - these are the hours in which can be used. Each instance in the report has its own field $F{Hours}. I will need to somehow continuously subtract from $V{TotalHours}.

For example:

  • Total Hours = 100

  • the first record will be 100 - hours

  • the second record will be ^that new number - hours

  • the third record will be ^that new number - hours

  • etc..

kind of confusing.. Any ideas?


Solution

  • Create a second variable $V{SumHours}. The expression for this variable should be $F{Hours} and the type SUM.

    If your data is shown in the Detail band, you can set a text field or another variable to $V{TotalHours} - $V{SumHours}. Since the Detail band is filled row by row, this calculation would work.

    NOTE: The variable $V{TotalHours} has to be previously filled before using it in the Detail band.