Focal Point
[CLOSED]Report with rolled up values.

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

January 19, 2017, 08:49 AM
Shankar
[CLOSED]Report with rolled up values.
Hi,
We have a requirement where we have to roll-up values for a particular case.
Example: I have a HOLD file with below set of data:
  
Transaction Id	Transaction Amount
1	        100
1	        20
1	        50
2	        100
2	        -30
3	        10
3	        -20
3	        30


The Report output will look like:

 
Transaction Id	Transaction Amount
1	        100
1	        20
1	        50
2	        70
3	        20
 


The report should sum-up values only when there is negative value for Transaction id
In example above, For Transaction id 1, there is no negative value. Hence it is displayed as it is but For transaction id 2 and 3, there are negative values, so in report output, Only one records is displayed for 2 and 3 with rolled up values.
Can some one please advise the way to achieve this?

Many Thanks.

This message has been edited. Last edited by: Tamra,


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML
January 19, 2017, 09:40 AM
Francis Mariani
here's some code:

-SET &ECHO=ON;

SET HOLDLIST=PRINTONLY
SET BYDISPLAY=ON
-RUN

-*-- Create the master for shankar1
FILEDEF DATAMAST DISK SHANKAR1.MAS
-RUN

-WRITE DATAMAST FILE=SHANKAR1, SUFFIX=FIX, $
-WRITE DATAMAST SEGNAME=SHANKAR1, SEGTYPE=S0, $
-WRITE DATAMAST FIELD=TX_ID , ALIAS=TX_ID , USAGE=A1, ACTUAL=A1, $
-WRITE DATAMAST FIELD=FILL1 , ALIAS=FILL1 , USAGE=A1, ACTUAL=A1, $
-WRITE DATAMAST FIELD=TX_AMT, ALIAS=TX_AMT, USAGE=I3, ACTUAL=A3, $

-*-- Create the data file for shankar1
FILEDEF SHANKAR1 DISK shankar1.ftm
-RUN
-WRITE SHANKAR1 1 100
-WRITE SHANKAR1 1 020
-WRITE SHANKAR1 1 050

-WRITE SHANKAR1 2 110
-WRITE SHANKAR1 2 060
-WRITE SHANKAR1 2 020

-WRITE SHANKAR1 3 100
-WRITE SHANKAR1 3 -30

-WRITE SHANKAR1 4 090
-WRITE SHANKAR1 4 -10

-WRITE SHANKAR1 5 017
-WRITE SHANKAR1 5  22
-WRITE SHANKAR1 5 130

-WRITE SHANKAR1 6 010
-WRITE SHANKAR1 6 -20
-WRITE SHANKAR1 6 030

-WRITE SHANKAR1 7 -10
-WRITE SHANKAR1 7 020
-WRITE SHANKAR1 7 040

-*-- ensure the data is in the correct order (by TX_ID and negatives need to be first)
TABLE FILE SHANKAR1
PRINT
TX_ID
TX_AMT
BY TX_ID    NOPRINT
BY TX_AMT   NOPRINT

ON TABLE HOLD AS HOLD_SHANKAR1
END
-RUN

-*-- Create the report
DEFINE FILE HOLD_SHANKAR1
AGGREGATE_IND/A1 = IF AGGREGATE_IND EQ 'Y' AND TX_ID EQ LAST TX_ID THEN 'Y' ELSE IF TX_AMT LT 0 THEN 'Y' ELSE 'N';
SORT_COL/I9 = IF AGGREGATE_IND EQ 'N' THEN SORT_COL + 1 ELSE SORT_COL;
END
-RUN

TABLE FILE HOLD_SHANKAR1
SUM
TX_AMT
BY TX_ID
BY SORT_COL NOPRINT
END
-RUN

The data needs to be in the correct order - by Transaction ID, with negative values for each Transaction ID before positive values. Then, using the LAST function, determine whether the data should be aggregated or not - if no aggregation, increment a secondary sort column; if aggregation leave the sort column value the same. I have additional cases in my example to make sure it worked.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
January 24, 2017, 10:31 AM
Francis Mariani
I hear crickets...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
January 27, 2017, 01:36 PM
Tamra
Shankar,

Did Francis's example help you with your question? Add it into a focexec and run it. Take the NOPRINT off the BY SORT_COL to see how this sorts the data for you.

You can apply the HOLD and DEFINE section to your existing report.


Thank your for participating in the Focal Point Forum,

Tamra Colangelo
Focal Point Moderator
Information Builders


WebFOCUS 8x - BI Portal, Developer Studio, App Studio, Excel, PDF, Active Formats and HTML5