How to: |
Reference: |
The summary commands SUBTOTAL, SUB-TOTAL, SUMMARIZE, and RECOMPUTE can be used with horizontal sort breaks.
When a request has multiple display fields and an ACROSS sort field, the report output has multiple columns under each ACROSS value. If you want to apply a summary field to some of the columns for each ACROSS value, but not others, you can specify the field names you want summarized. This technique is most useful for report requests that use the OVER phrase to place the fields on separate rows
{ACROSS|ON} acrossfield [AS 'text1'] sumoption [AS 'text2'] [COLUMNS c1 [AND c2 ...]]
or
ACROSS acrossfieldsumoption [field1field2 ... fieldn]
or
ACROSS acrossfield
ON acrossfieldsumoption [field1field2 ... fieldn]
where:
Are the fields that will have the summary command applied. If no fields are listed, all fields will be summarized.
The following request sums units and dollars and calculates the unit cost by product and across region and month. The ACROSS MNTH RECOMPUTE command creates totals of units and dollars, and recomputes the calculated value for the selected months within regions. The ACROSS REGION RECOMPUTE command does the same for the selected regions. The ON TABLE SUMMARIZE command creates summary rows. It has no effect on columns:
DEFINE FILE GGSALES MNTH/MTr = DATE; END TABLE FILE GGSALES SUM UNITS/I5 AS 'UNITS' OVER DOLLARS/I6 AS 'DOLLARS' OVER COMPUTE DOLLPER/I6 = DOLLARS/UNITS; AS 'UNIT COST' BY PRODUCT ACROSS REGION RECOMPUTE AS 'Region Sum' COLUMNS 'Northeast' AND 'West' ACROSS MNTH RECOMPUTE AS 'Month Sum' COLUMNS 'November' AND 'December' WHERE DATE FROM '19971101' TO '19971231'; WHERE PRODUCT EQ 'Capuccino' OR 'Espresso'; ON TABLE SUMMARIZE AS 'Grand Total' END
The output is:
The following request against the GGSALES data source sums the DOLLARS and UNITS fields by CATEGORY and across REGION, but subtotals only the UNITS field.
TABLE FILE GGSALES SUM DOLLARS AS 'Dollars' OVER UNITS AS 'Units' BY CATEGORY ACROSS REGION SUBTOTAL UNITS WHERE REGION EQ 'Midwest' OR 'West' ON TABLE SET PAGE NOPAGE END
The output shows that only the rows with the UNITS values are subtotaled.
Region Midwest West TOTAL Category ------------------------------------------------------------- Coffee Dollars 4178513 4473517 Units 332777 356763 689540 Food Dollars 4338271 4202337 Units 341414 340234 681648 Gifts Dollars 2883881 2977092 Units 230854 235042 465896
The following request against the GGSALES data source sums the DOLLARS and UNITS fields and calculates DOLLARS PER UNIT across REGION. The request also has a higher-level ACROSS field, CATEGORY, so the SUMMARIZE command propagates to both ACROSS fields.
SET BYPANEL = ON TABLE FILE GGSALES SUM DOLLARS AS 'Dollars' OVER UNITS AS 'Units' OVER AND COMPUTE DPERU/D9.2 = DOLLARS/UNITS; ACROSS CATEGORY ACROSS REGION ON REGION SUMMARIZE DPERU WHERE REGION EQ 'Midwest' OR 'West' WHERE CATEGORY EQ 'Food' OR 'Gifts' ON TABLE PCHOLD FORMAT PDF END
The first panel of output shows:
PAGE 1.1 Category Food Gifts Region Midwest West TOTAL Midwest West ------------------------------------------------------------------------- Dollars 4338271 4202337 2883881 2977092 Units 341414 340234 230854 235042 DPERU 12.71 12.35 12.53 12.49 12.67
The second panel has the total column for the Gifts category and the grand total column. Each of those only has a value in the DPERU row.
PAGE 1.2 Category TOTAL Region TOTAL ---------------------------------- Dollars Units DPERU 12.58 12.55
The following request against the GGSALES data source sums the DOLLARS and UNITS fields ACROSS CATEGORY and ACROSS REGION, with a SUMMARIZE command on the REGION field. The request also has a higher-level ACROSS field, CATEGORY, so the SUMMARIZE command propagates to both ACROSS fields. The SUMMARIZE command specifies the AVE. prefix operator for the DOLLARS field.
SET BYPANEL = ON TABLE FILE GGSALES SUM DOLLARS AS 'Dollars' OVER UNITS AS 'Units' ACROSS CATEGORY ACROSS REGION ON REGION SUMMARIZE AVE. DOLLARS WHERE REGION EQ 'Midwest' OR 'West' WHERE CATEGORY EQ 'Food' OR 'Gifts' ON TABLE PCHOLD FORMAT PDF END
The first panel of output shows:
PAGE 1.1 Category Food Gifts Region Midwest West TOTAL Midwest West ------------------------------------------------------------------------- Dollars 4338271 4202337 4270304 2883881 2977092 Units 341414 340234 230854 235042
The second panel has the total column for the Gifts category and the grand total column. Each of those only has a value in the DOLLARS row.
PAGE 1.2 Category TOTAL Region TOTAL ---------------------------------- Dollars 2930486 3600395 Units
The following request against the GGSALES data source sums the DOLLARS and UNITS fields ACROSS CATEGORY and ACROSS REGION, with a SUMMARIZE command on the REGION field and a SUBTOTAL command on the CATEGORY field. The SUMMARIZE command specifies average DOLLARS and minimum UNITS. The SUBTOTAL command specifies minimum DOLLARS.
SET BYPANEL = ON TABLE FILE GGSALES SUM DOLLARS AS 'Dollars' OVER UNITS AS 'Units' ACROSS CATEGORY ACROSS REGION ON CATEGORY SUBTOTAL MIN. DOLLARS ON REGION SUMMARIZE AVE. DOLLARS MIN. UNITS WHERE REGION EQ 'Midwest' OR 'West' WHERE CATEGORY EQ 'Food' OR 'Gifts' ON TABLE PCHOLD FORMAT PDF END
On the output, all of the TOTAL columns have the minimum UNITS. The TOTAL columns associated with the REGION sort field have the average DOLLARS, but the TOTAL column associated with the CATEGORY sort field has the minimum DOLLARS because SUMMARIZE does not change the prefix operator associated with a higher-level sort field.
PAGE 1.1 Category Food Gifts Region Midwest West TOTAL Midwest West ------------------------------------------------------------------------- Dollars 4338271 4202337 4270304 2883881 2977092 Units 341414 340234 340234 230854 235042
PAGE 1.2 Category TOTAL Region TOTAL ---------------------------------- Dollars 2930486 2883881 Units 230854 230854