Sum and division expression

Hi,

I have a query that returns something like:

Help      Year     num

1               1           12

2               1           35

3               1           46

4               1           3

1               2           23

2               2           67

3               2           39

4               2           17

1               3           37

2               3          65

3               3           11

4               3           54

 

I want to make a chart showing: 

num_help1_year1/sum(num_year1), num_help2_year1/sum(num_year1), ...

...

num_help1_year4/sum(num_year4), num_help2_year4/sum(num_year4)...

 

But idk how to make a sum and a division... an also idk how to make the sum for each year.

Anyone can help me?

 

 I'm using iReport 3.7.2.

Sorry, I'm spanish and my english is not really good.



Post Edited by sgarciaf at 05/20/2010 10:57
sgarciaf's picture
482
Joined: May 10 2010 - 1:29am
Last seen: 10 years 4 months ago

3 Answers:

for the sum try to study variables (calculation type: SUM)...

for division the syntax changes if you use Integer or BidDecimal or ... the types that you use to represent the fields from your DB.

try to be more clear in the question...

 

a very simple way is:
$F{aFieldName_A}.intValue() / $F{aFieldName_B}.intValue()

 

 

 

 

slow's picture
6599
Joined: Feb 17 2010 - 6:57am
Last seen: 13 years 3 months ago

Thanks slow,

My variables are Long type.

sgarciaf's picture
482
Joined: May 10 2010 - 1:29am
Last seen: 10 years 4 months ago

Long class doesn't have method to perform division... so you can use primitive values:

$F{fieldName_A}.intValue() / $F{fieldName_B}.intValue()

or

$F{fieldName_A}.longValue() / $F{fieldName_B}.longValue()

 

 

 

 

 

slow's picture
6599
Joined: Feb 17 2010 - 6:57am
Last seen: 13 years 3 months ago
Feedback
randomness