SUM conditional Jasper Reports

Asked

Viewed 841 times

1

I’m using Jaspersoft Studio. In Summary I want to display the totalizer of a field, but using the SUM function (which the JS provides when I drag the field) I cannot add by a given condition.

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

1 answer

1

Create a variable in your report by placing the field Calculation for Sum and the countryside Value Class Name for java.lang.Integer. On the field Expression place the following condition: $F{ocorrência} == 28 ? $F{valor} : new Integer(0)

This solution will work but bear in mind that the more complex testing logic should not be in the report but in its code. If you have to do many conditions like this think about the possibility of calculating this before passing the data to Jasper and inform them already calculated through parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.