Calculate a percentage

0

Hi, I'm new to Jaspersoft and HTML / Java so everything I am doing is a bit of a shot in the dark, but I'm really stuck on something that feels like it should be simple.

I have calculated some fields in the SQL to count the total cases within deadline and the total cases per team and put them in an ad hoc table. This looks to be working fine.

I now want to add an extra column that calculates the percentage that are completed on time, i.e. $F{CompletedWithinDeadline}/$F{TotalCases}*100

I have tried putting this formula in a text field and I have tried creating a variable, but both just show 0 when placed in the details part of the table.

I'm stumped. This seems such a simple thing but much experimenting and searching for answers here has yielded nothing. Any help gratefully received!

jonathan.brooker's picture
Joined: Oct 22 2019 - 2:57am
Last seen: 2 weeks 1 day ago

If you are using java.math.BigDecimal as your class you will need to use .divide and .multiply

$F{CompletedWithinDeadline}.divide($F{TotalCases}).multiply(100)

luked - 2 weeks 1 day ago

1 Answer:

0

I had the same problem getting percentages to work so I just calculated it in the query using this and made it a field.

          CAST(ROUND(100-(sum(OverdueCount) * 100.0 / sum(TotalCount)), 2) as decimal(10,2)) AS PercentCompliance
 

james.jordan's picture
Joined: Feb 26 2015 - 7:27am
Last seen: 1 day 15 hours ago
Feedback
randomness