Focal Point
[SOVLED] Sort on sum field

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

November 12, 2010, 12:48 AM
JOE
[SOVLED] Sort on sum field
This seems like it would be easy but I'm having problems. I have two by fields A and B and a sum field C. All I want to do is sort C by Desc so report should look like

A B C
GGG ffff 45
hhhh 41
vvv hhhh 67
dddd 45
ect..

code :

TABLE FILE SQLOUT
SUM 
     TRANSCOUNT
BY TOTAL HIGHEST TRANSCOUNT NOPRINT
BY EmpDivisionName
BY DNIS
HEADING
""
FOOTING
""
ON TABLE SET PAGE-NUM OFF 
ON TABLE COLUMN-TOTAL AS 'TOTAL' TRANSCOUNT
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *  


Any help would be much appreciated!

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


WebFocus 7.7.02 WinXP
November 12, 2010, 01:00 AM
Dan Satchell
Your post is a little confusing because the sample output you provide is not sorted by column C in descending order. But assuming that is what you want, here is an example using the CAR file that seems to work.

TABLE FILE CAR
 SUM
  COMPUTE PROFIT/D7 = RETAIL_COST - DEALER_COST ;
 BY TOTAL HIGHEST PROFIT NOPRINT
 BY COUNTRY
 BY CAR
 ON TABLE COLUMN-TOTAL AS 'TOTAL' PROFIT
END



WebFOCUS 7.7.05
November 12, 2010, 08:00 AM
JOE
Thanks, however this is not what I was looking for. My example did not come out right. The output needs to go in this order:
By field A (sorted)
By field B (sorted)
Sum field C (sorted desc)

Sum Field C needs to be sorted Desc. Your example sorts by profit first and does not keep the by fields together.

I'll try example again: Thanks!
 Division    DNIS     Sum
aaaaa       7778     780
            8889     741
			9999     600
bbbbb       7778     550
            8889     400
ccccc       7778     500 



WebFocus 7.7.02 WinXP
November 12, 2010, 10:39 AM
T.Peters
So, you want

BY DIVISION
BY PROFIT

correct?


WebFOCUS: 7702
O/S : Windows
Data Migrator: 7702
November 12, 2010, 10:39 AM
Baillecl
Bonjour,
Something new occured while I was not at watch ?

IF TOTAL and WHERE TOTAL is possible since the point is just not to take into account the lines of the Internal Matrix (Agregated) that do not meet the where Total condition(s).

But, to ReSort the internal Matrix according to the result of the process of Agregation (BY TOTAL) surprises me.

Stackhanov and I used to Hold the result of the agregated data ( Not BY TOTAL Sorted yet)
And to Write the intended BY on the intermediate Hold File (BY at this point are de facto BY TOTAL of previous Step).
In Fact, Stackanoff and I, did that also about IF TOTAL when IF Total did not yet exist ...
(A time that youngsters just can't fancy ... "La Boheme" by Charles Aznavour)
Cordially
By the way, I fear that Stackhanoff is dead, and myself is not so brilliant as it used to be -if ever...
***
The Agregation can also be made at the SQL level with GROUP BY, and then at the Table File SQLOUT level a simple, Usual, BY
would sort on pre-agregated value


Focus Mainframe 7.6.11
Dev Studio 7.6.11 and !!!
PC Focus, Focus for OS/2, FFW Six, MSO
November 12, 2010, 11:52 AM
JOE
T...I want By Division then By DNIS. Profit is probably from the earlier example


WebFocus 7.7.02 WinXP
November 12, 2010, 02:54 PM
Crymsyn
I am not sure if this is more what you are looking for JOE but is this more what you want the output to be like?

(Using Dan's Car example)
 TABLE FILE CAR
 SUM
  COMPUTE PROFIT/D7 = RETAIL_COST - DEALER_COST ; AS 'Sum'
 BY COUNTRY AS 'Division'
 BY TOTAL HIGHEST PROFIT NOPRINT
 BY CAR	AS 'DNIS'
 ON TABLE COLUMN-TOTAL AS 'TOTAL' PROFIT
END
 



WF: 8201, OS: Windows, Output: HTML, PDF, Excel
November 13, 2010, 10:14 AM
Brian Suter
Is DNIS a "summed" field.
To go back to your example at 8am.
IF A and B are both fields from the database and you are SUMMING C then there is only ONE c value for any A&B combination. A sort of ONE value always comes out in the same order!
SUM C BY A BY B


Brian Suter
VP WebFOCUS Product Development
November 15, 2010, 01:44 PM
JOE
Thanks for all your help..I figured it out. I did the sum on a FOCUS hold and then did the grouping only at div level on next table.

Code below:

 ENGINE SQLMSS SET DEFAULT_CONNECTION IVB
SQL SQLMSS
EX ORBIT.dbo.CallTransDetail '&dte','&edte'
;
TABLE FILE SQLOUT
PRINT *
ON TABLE HOLD AS SQLOUT
END
TABLE FILE SQLOUT
SUM
     TRANSCOUNT
BY TOTAL HIGHEST TRANSCOUNT NOPRINT
BY EmpDivisionName
BY DNIS
HEADING
""
FOOTING
""
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
ON TABLE HOLD AS DIV FORMAT FOCUS
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *

END
TABLE FILE DIV
PRINT
     DNIS AS 'Transfer,No.'
     TRANSCOUNT AS 'Call,Count'
BY EmpDivisionName AS 'Division'

ON EmpDivisionName SUBTOTAL AS '*TOTAL'
HEADING
"PNC Call Center "
"Call Transfer Detail Report"
"&dte<+0> through <+0>&edte"
FOOTING
""
ON TABLE SET PAGE-NUM OFF
ON TABLE SET EXPANDABLE ON
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE * 



WebFocus 7.7.02 WinXP