Focal Point
running total

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9661097172

February 15, 2008, 01:06 PM
Noel
running 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!


WebFocus 762 AS400 / DB2
February 15, 2008, 01:18 PM
Darin Lee
LAST 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


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
February 15, 2008, 01:18 PM
Alan B
Noel

Try this, using LAST:
TABLE FILE CAR
SUM SALES
COMPUTE RUNNING_TOTAL = SALES + LAST RUNNING_TOTAL;
BY COUNTRY
END



Alan.
WF 7.705/8.007
February 15, 2008, 03:25 PM
Noel
quote:
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


WebFocus 762 AS400 / DB2
February 15, 2008, 03:44 PM
mgrackin
Noel,

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


Thanks!

Mickey

FOCUS/WebFOCUS 1990 - 2011
February 15, 2008, 05:31 PM
Noel
Guys,

Thanks a lot for the help. Your suggestions works


WebFocus 762 AS400 / DB2
September 19, 2008, 06:53 PM
Doug
Thanks Mickey: I had a brain freeze on this and your sample thawed it out...
-Doug