conditional SUM Jasper Reports

0

I'm using JasperSoft Studio. In Summary I want to display the totalizer of a field, however using the SUM function (which JS provides when I drag the field) I can not add a given condition.

What I wanted was something like, adding the $ F {value} field when $ F {occurrence} was different from the "28".

    
asked by anonymous 07.08.2018 / 16:13

1 answer

0

Create a variable in your report by setting the Calculation field to Sum and the Value Class Name field to java.lang.Integer . In the Expression field, enter the following condition: $F{ocorrência} == 28 ? $F{valor} : new Integer(0)

This solution will work but take into account that the more complex testing logic should not be in the report but in your code. If you have to do many conditions like this think of the possibility of calculating this before passing the data to the jasper and informing them already calculated through parameter.

    
01.09.2018 / 03:16