February 15, 2008, 01:06 PM
Noelrunning total
how to compute for the running total in a report?
ITEM AMOUNT TOTAL AMOUNT
AAAA 123.00 123.00
BBBB 100.00 223.00
CCCC 50.00 273.00
i though using the LAST function will solve the problem but it won't since the AMOUNT column is the sum of all same items.
thanks in advance for all the help!
February 15, 2008, 01:18 PM
Darin LeeLAST is the right answer:
TABLE FILE CAR
SUM RCOST
COMPUTE RUN_TOT=LAST RUN_TOT + RCOST;
BY COUNTRY
END
gets you
COUNTRY RETAIL_COST RUN_TOT
ENGLAND 45,319 45,319.00
FRANCE 5,610 50,929.00
ITALY 51,065 101,994.00
JAPAN 6,478 108,472.00
W GERMANY 64,732 173,204.00
February 15, 2008, 01:18 PM
Alan BNoel
Try this, using LAST:
TABLE FILE CAR
SUM SALES
COMPUTE RUNNING_TOTAL = SALES + LAST RUNNING_TOTAL;
BY COUNTRY
END
February 15, 2008, 03:25 PM
Noelquote:
LAST RUN_TOT
Thanks a lot for the ideas that you shared.
I missed to mention one thing in one of the colums we use the PCT prefix to cumpute for the percentage. here are the actual codes that i have.
TABLE FILE MBF9REP
SUM
'AVE.MBDDREP.MBDDREP.AvePrice' AS 'Average, Price'
'MBDDREP.MBDDREP.DDARQT' AS 'Overall, Sales, (Units)'
'MBDDREP.MBDDREP.DDDUVA' AS 'Consumption, Value($)'
'PCT.MBDDREP.MBDDREP.DDDUVA' AS 'Consumption,Value(%)'
COMPUTE CNSPCT/D12.2 = LAST CNSPCT + PCT.MBDDREP.MBDDREP.DDDUVA;
RANKED AS 'RANK' BY TOTAL HIGHEST 'MBDDREP.MBDDREP.DDDUVA' NOPRINT
BY 'MBDDREP.MBDDREP.DDAITX'
when i run the report its not showing the correct figure to be displayed in the CNSPCT column.
thanks again
February 15, 2008, 03:44 PM
mgrackinNoel,
Your code is technically correct. The problem here is that you are trying to do two things in one pass of the data which are interferring with each other. The BY TOTAL HIGHEST sort is done last AFTER COMPUTEs. Therefore your running total is being calculated before the final sort which then rearranges the order. You need to create a HOLD file first with the aggregated values and then do another TABLE FILE using the HOLD file to get your final results.
Here's a working example with the CAR database.
TABLE FILE CAR
SUM AVE.RCOST AS 'AVERCOST'
SALES
WEIGHT
PCT.SALES AS 'PCTSALES'
BY COUNTRY
ON TABLE HOLD AS STEPONE
ON TABLE SET ASNAMES ON
END
-RUN
TABLE FILE STEPONE
PRINT AVERCOST
SALES
WEIGHT
PCTSALES
COMPUTE RUNTOT/D12.2=LAST RUNTOT + PCTSALES;
RANKED AS 'RANK' BY HIGHEST SALES
BY COUNTRY
END
February 15, 2008, 05:31 PM
NoelGuys,
Thanks a lot for the help. Your suggestions works
September 19, 2008, 06:53 PM
DougThanks Mickey: I had a brain freeze on this and your sample thawed it out...
-Doug