Report Totals

This information describes ways to explicitly assign the aggregation rule for report totals, which helps improve performance, and is intended specifically for technical developers writing reports with Oracle Analytics.

In this example, the report definition is year, month, and customer region, with a metric 'Count Distinct of Customers with Orders', which is defined as a count distinct of customers with orders.

Description of ceal_report_totals_example.jpg follows
Description of the illustration ceal_report_totals_example.jpg

Here's the logical query:

SELECT
   0 s_0,
   "A - Sample Sales"."Cust Regions"."C50  Region" s_1,
   "A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" s_2,
   REPORT_AGGREGATE("A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" BY ) s_3
FROM "A - Sample Sales"
WHERE
("Time"."T02 Per Name Month" = '2011 / 11')
ORDER BY 2 ASC NULLS LAST
FETCH FIRST 500001 ROWS ONLY

Here's the physical query that's generated:

WITH
SAWITH0 AS (select count(distinct T42433.Cust_Key) as c1,
     T42430.Region as c2
from
     BISAMPLE.SAMP_CUSTOMERS_D T42428 /* D60 Customers */ ,
     BISAMPLE.SAMP_ADDRESSES_D T42430 /* D62 Customers Addresses */ ,
     BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ ,
     BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */
where  ( T42405.Mth_Key = T42433.Bill_Mth_Key and T42405.Per_Name_Month = '2011 / 11' and T42428.Cust_Key = T42433.Cust_Key and T42428.Address_Key = T42430.Address_Key )
group by T42430.Region),
SAWITH1 AS (select count(distinct T42433.Cust_Key) as c1
from
     BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ ,
     BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */
where  ( T42405.Per_Name_Month = '2011 / 11' and T42405.Mth_Key = T42433.Bill_Mth_Key ) )
select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from ( select D1.c1 as c1,
     D1.c2 as c2,
     D1.c3 as c3,
     D1.c4 as c4
from
     (select 0 as c1,
               D1.c2 as c2,
               D1.c1 as c3,
               D2.c1 as c4,
               ROW_NUMBER() OVER (PARTITION BY D1.c2 ORDER BY D1.c2 ASC) as c5
          from
               SAWITH0 D1,
               SAWITH1 D2
     ) D1
where  ( D1.c5 = 1 )
order by c2 ) D1 where rownum <= 500001

The total value, 480, is the sum of the constituent values, 182 + 113 + 185. The logical query expression that calculates the total is: “REPORT_AGGREGATE("A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" BY ) s_3”.

When “REPORT_AGGREGATE” is used, the total will be calculated independently of the constituent values. But for this report design, we determined that the correct total can be calculated from the constituents for this report.

Edit the column formula to change the “Aggregation Rule (Totals Row)” from “Server Complex Aggregate” to “Sum”. This changes the logical and physical SQL.

Original aggregation:

Description of ceal_original_aggregation.jpg follows
Description of the illustration ceal_original_aggregation.jpg

Modified aggregation:

Description of ceal_modified_aggregation.jpg follows
Description of the illustration ceal_modified_aggregation.jpg

The modified logical SQL now has “REPORT_SUM”.

SELECT
   0 s_0,
   "A - Sample Sales"."Cust Regions"."C50  Region" s_1,"A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" s_2,
   REPORT_SUM("A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" BY ) s_3
FROM "A - Sample Sales"
WHERE
("Time"."T02 Per Name Month" = '2011 / 11')
ORDER BY 2 ASC NULLS LAST
FETCH FIRST 500001 ROWS ONLY

Here's the physical query that's generated:

WITH
SAWITH0 AS (select count(distinct T42433.Cust_Key) as c1,
     T42430.Region as c2
from
     BISAMPLE.SAMP_CUSTOMERS_D T42428 /* D60 Customers */ ,
     BISAMPLE.SAMP_ADDRESSES_D T42430 /* D62 Customers Addresses */ ,
     BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ ,
     BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */
where  ( T42405.Mth_Key = T42433.Bill_Mth_Key and T42405.Per_Name_Month = '2011 / 11' and T42428.Cust_Key = T42433.Cust_Key and T42428.Address_Key = T42430.Address_Key )
group by T42430.Region),
SAWITH1 AS (select 0 as c1,
     D1.c2 as c2,
     D1.c1 as c3
from
     SAWITH0 D1)
select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from ( select D1.c1 as c1,
     D1.c2 as c2,
     D1.c3 as c3,
     sum(D1.c3) over ()  as c4
from
     SAWITH1 D1
order by c2 ) D1 where rownum <= 500001

The same option to explicitly set the aggregation is available in workbooks:

Description of ceal_workbook_set_aggregation.jpg follows
Description of the illustration ceal_workbook_set_aggregation.jpg

Review your reports to see that the best aggregation rule is being used for the report. Use an explicit aggregation rule when the report design allows it.

For more information about reports, see Create Analyses.