welsa.chy Posted March 5, 2013 Share Posted March 5, 2013 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_Vehicles1 Car 10002 Lorry 2003 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.IntegerCalculation:SumVariable 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 More sharing options...
ajinkya_c Posted March 5, 2013 Share Posted March 5, 2013 Create three variablesVar1(CAR)=Number of vehiclesVar2(Truck)=Number of VehiclesVar3(Total)=Var1+Var2 Link to comment Share on other sites More sharing options...
shravanmudumba Posted March 5, 2013 Share Posted March 5, 2013 try adding in the query by using a if case and a view...I have dont in the similar way .I couldnt find the solution ....the condition is wrong$F{ID}== 1 || $F{Type}==3 use id instead of type .. but I dont think that will help you Link to comment Share on other sites More sharing options...
welsa.chy Posted March 5, 2013 Author Share Posted March 5, 2013 Thank you ajinkya_c for your response :) I created a variable TOTAL_TRUCK with the variable expression ($F{ID}==3 ? $F{Number_of_Vehicles} : 0 ) and tried to display it .. its returning me a "0" Link to comment Share on other sites More sharing options...
Solution jatinb Posted March 7, 2013 Solution Share Posted March 7, 2013 Hi welsa.chy, 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 More sharing options...
welsa.chy Posted March 7, 2013 Author Share Posted March 7, 2013 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 More sharing options...
jatinb Posted March 7, 2013 Share Posted March 7, 2013 What is the RESET type set for "TOTAL" variable? Link to comment Share on other sites More sharing options...
welsa.chy Posted March 11, 2013 Author Share Posted March 11, 2013 My RESET TYPE is set to "None" is it okey? Link to comment Share on other sites More sharing options...
welsa.chy Posted March 11, 2013 Author Share Posted March 11, 2013 Thank you so much Jatinb.. if you didn't mentioned the reset type i would have never thought about it. I am new to jaspersoft. The RESET TYPE should be set to "Report". Link to comment Share on other sites More sharing options...
saroj.shandilya Posted October 26, 2016 Share Posted October 26, 2016 ( $F{ID}== 1 || $F{ID}==3 ? $V{Number_of_Vehicles} : 0 ) Link to comment Share on other sites More sharing options...
saroj.shandilya Posted October 26, 2016 Share Posted October 26, 2016 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 ) RegardsSaroj Jha Link to comment Share on other sites More sharing options...
saroj.shandilya Posted October 26, 2016 Share Posted October 26, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now