Jump to content
We've recently updated our Privacy Statement, available here ×

Sum on specific rows in iReport


welsa.chy
Go to solution Solved by jatinb,

Recommended Posts

Hi Eeveryone,

i've been stuck on that for days now..

I have a report where i am displaying data as below:

ID      Type       Number_of_Vehicles

1       Car        1000

2       Lorry      200

3       Truck     400

 

I would like to sum only the Type "Car" and "Truck".

I created a new variable named TOTAL, then the below properties:

Variable Class: java.lang.Integer

Calculation:Sum

Variable Expression: ( $F{ID}== 1 || $F{ID}==3 ? $F{Number_of_Vehicles} : 0 )

But it gives me the last number that is "400"

Can anyone figure this out?

Thank you so much..

 

Link to comment
Share on other sites

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

 

Which is the band where you have placed the "TOTAL" variable i.e. Column Footer, Page footer or Summary?  What is the Reset type for the "TOTAL" variable (ideally it should be Report if in Summary Band)

 

The Variable Expression- ( $F{ID}== 1 || $F{ID}==3 ? $F{Number_of_Vehicles} : 0 ) or even

( $F{Type}== "Car" || $F{Type}== "Truck" ? $F{Number_of_Vehicles} : 0 )  should work for you.

 

Let me know if this works.

 

Regards,

Jatin

 

Link to comment
Share on other sites

Hi Jatinb, yea i placed it in all of the bands.. but it would not work.. :( in fact i have a stored procedure which is returning me these data. and i tried putting it in the summary band. the TOTAL Variable is returning me "0" when i put ($F{ID}==1 ? $F{Number_of_Vehicles} : 0 ) in the variable expression and it is giving me a "400"(the last value of the field[Number_of_Vehicles] obviously) when i put ($F{ID}==3 ? $F{Number_of_Vehicles} : 0 ).
Link to comment
Share on other sites

  • 3 years later...

Hi,

 

You can keep any no of condition. just update ur variable expression like below then use variable in footer or summary. dont change exp once you dragged it to ur column footer. If you need t modify change ur variable exp instead of field in footer

( $F{ID}== 1 || $F{ID}==3 ? $V{Number_of_Vehicles} : 0 ) 

 

Regards

Saroj Jha

Link to comment
Share on other sites

Hi,

 

 

 

You can keep any no of condition. just update ur variable expression like below then use variable in footer or summary. dont change exp once you dragged it to ur column footer. If you need t modify change ur variable exp instead of field in footer

 

( $F{ID}== 1 || $F{ID}==3 ? $V{Number_of_Vehicles} : 0 )

 

 

 

Regards

 

Saroj Jha

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...