Summing columns to give a grand total

Hi,
I'm sure this is simple using one of the GROUP BY extensions, but I'm having a particularly dumb day
I have the following SQL
  SELECT EGROUP.EDESC,
         SUM(DECODE(PERS.AGERANGE,'UNDER 16',1,0)) AS "UNDER 16",
         SUM(DECODE(PERS.AGERANGE,'16 - 25',1,0)) AS "16 - 25",
         SUM(DECODE(PERS.AGERANGE,'26 - 35',1,0)) AS "26 - 35",
         SUM(DECODE(PERS.AGERANGE,'36 - 45',1,0)) AS "36 - 45",
         SUM(DECODE(PERS.AGERANGE,'46 - 59',1,0)) AS "46 - 59",
         SUM(DECODE(PERS.AGERANGE,'60 +',1,0)) AS "60 +",
         SUM(DECODE(PERS.AGERANGE,'UNKNOWN',1,0)) AS "UNKNOWN",
         COUNT(PERS.PIN) AS "Total"
    FROM (SELECT 1 ORD, 'WBRI' ECODE, 'White British' EDESC FROM DUAL UNION ALL
          SELECT 2, 'WENG', 'White English' FROM DUAL UNION ALL
          SELECT 3, 'WSCO', 'White Scottish' FROM DUAL UNION ALL
          SELECT 4, 'WWEL', 'White Welsh' FROM DUAL UNION ALL
          SELECT 5, 'WIRI', 'White Irish' FROM DUAL UNION ALL
          SELECT 6, 'WOTH', 'White Other' FROM DUAL
         ) EGROUP,
         (SELECT 1234 PIN, 'WBRI' PCODE, 'UNDER 16' AGERANGE FROM DUAL UNION ALL
          SELECT 1235, 'WENG', '16 - 25' FROM DUAL UNION ALL
          SELECT 1236, 'WENG', '16 - 25' FROM DUAL
         ) PERS
   WHERE EGROUP.ECODE = PERS.PCODE(+)  
GROUP BY EGROUP.EDESC, EGROUP.ORD
ORDER BY EGROUP.ORD ASC  which produces
White British  1 0 0 0 0 0 0 1
White English  0 2 0 0 0 0 0 2
White Scottish 0 0 0 0 0 0 0 0
White Welsh    0 0 0 0 0 0 0 0
White Irish    0 0 0 0 0 0 0 0
White Other    0 0 0 0 0 0 0 0what I'd like is for a 'totals row' to also be output
White British  1 0 0 0 0 0 0 1
White English  0 2 0 0 0 0 0 2
White Scottish 0 0 0 0 0 0 0 0
White Welsh    0 0 0 0 0 0 0 0
White Irish    0 0 0 0 0 0 0 0
White Other    0 0 0 0 0 0 0 0
Total          1 2 0 0 0 0 0 3I really need to read the Data Warehousing manual, to try and understand how CUBE, ROLLUP and grouping sets work.
Thanks
Dave

SQL>   SELECT nvl(EGROUP.EDESC,'Total'),
  2           SUM(DECODE(PERS.AGERANGE,'UNDER 16',1,0)) AS "UNDER 16",
  3           SUM(DECODE(PERS.AGERANGE,'16 - 25',1,0)) AS "16 - 25",
  4           SUM(DECODE(PERS.AGERANGE,'26 - 35',1,0)) AS "26 - 35",
  5           SUM(DECODE(PERS.AGERANGE,'36 - 45',1,0)) AS "36 - 45",
  6           SUM(DECODE(PERS.AGERANGE,'46 - 59',1,0)) AS "46 - 59",
  7           SUM(DECODE(PERS.AGERANGE,'60 +',1,0)) AS "60 +",
  8           SUM(DECODE(PERS.AGERANGE,'UNKNOWN',1,0)) AS "UNKNOWN",
  9           COUNT(PERS.PIN) AS "Total"
10      FROM (SELECT 1 ORD, 'WBRI' ECODE, 'White British' EDESC FROM DUAL UNION ALL
11            SELECT 2, 'WENG', 'White English' FROM DUAL UNION ALL
12            SELECT 3, 'WSCO', 'White Scottish' FROM DUAL UNION ALL
13            SELECT 4, 'WWEL', 'White Welsh' FROM DUAL UNION ALL
14            SELECT 5, 'WIRI', 'White Irish' FROM DUAL UNION ALL
15            SELECT 6, 'WOTH', 'White Other' FROM DUAL
16           ) EGROUP,
17           (SELECT 1234 PIN, 'WBRI' PCODE, 'UNDER 16' AGERANGE FROM DUAL UNION ALL
18            SELECT 1235, 'WENG', '16 - 25' FROM DUAL UNION ALL
19            SELECT 1236, 'WENG', '16 - 25' FROM DUAL
20           ) PERS
21     WHERE EGROUP.ECODE = PERS.PCODE(+)
22  GROUP BY grouping sets ((EGROUP.EDESC, EGROUP.ORD),())
23  ORDER BY EGROUP.ORD ASC
24  /
NVL(EGROUP.EDE UNDER 16  16 - 25  26 - 35  36 - 45  46 - 59     60 +  UNKNOWN    Total
White British         1        0        0        0        0        0        0        1
White English         0        2        0        0        0        0        0        2
White Scottish        0        0        0        0        0        0        0        0
White Welsh           0        0        0        0        0        0        0        0
White Irish           0        0        0        0        0        0        0        0
White Other           0        0        0        0        0        0        0        0
Total                 1        2        0        0        0        0        0        3
7 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • Hide column result in pivot grand total row

    Hello
    Do you know if it is possible to hide the result of a particular column in a pivot grand total row?
    I have several columns to which makes sense use a grand total row (as in a sum) but for others (such as average) it does not make sense in the light of the client business rules.
    Any help on this matter is highly appreciated :)
    Thanks in advance,
    J Marques

    I have a measure that represents the average time according to the dimensions it uses - and that works properly.
    However, the grand total for that column shows me the average of the average times above. This is not correct that is why I want to hide it.As said by kishore, In pivot go to that time average time column -> Aggregation rule -> None, This won't affect the column avg value.
    The grant total value will not come.
    By setting this, are you getting wrong values?
    Thanks,
    Vino

  • Pivot table - Grand total Error

    hi,
    I am getting incorrect totals in my Pivot table.
    i.e The Grand Total is not giving the exact sum.
    pls direct me..
    My scenario: I need to calculate the total expenses per region and quarterwise.

    i havent used any aggregation rule.
    In the Answers, i have designed the Pivot table in the below format
    [i simply drag-dropped the Columns]
    I should give the grand total regionwise and also quarterwise.but the grand totals arent displaying the proper results.
    pls advise.
    Ex:
    region          Q1     Q2     Q3     Region- Grand total
    AAA          20000     50000     120000     xxxxxxx
    BBB          22240     13456     111500     xxxxxxxxx
    Qtr-Grand Total     zzz     zzzz     zzzz     nnnnnnnnn

  • Grand total in OBIEE Answers

    I have say three columns in a report, Col A that aggregates by SUM, Col B that also aggregates by SUM and Col 3 that aggregates by Avg
    Col A Col B Col C
    Amount Qty Avg price
    10 3 3.33
    20 4 5
    30 7 ? Grand Total (use of report total)
    I want to see Sum (col A) / Sum Col B and average of Col C where I have ?, how can I do that?

    Hi,
    If i got you correctly,
    i think you can achieve this way.
    Criteria:
    Dim X, Dim Y, Col A , Col B , Col C
    case i:
    If Col A & Col B are Aggregated to SUM(in RPD),
    then in the column formula of 'Col C',
    Col A/Col B (Aggregation Rule - Default)
    This gives you the SUM(Col A) / SUM(Col B) for the Grand total Row for 'Col C'
    case ii:
    If Col A & Col B are Not Aggregated to SUM(in RPD),
    then in the column formula of 'Col C',
    SUM(Col A BY Dim X, Dim Y)
    SUM(Col B BY Dim X, Dim Y) (Aggregation Rule - Default)
    This gives you the SUM(Col A BY all Dim X,Y values) / SUM(Col B BY all Dim X,Y values) for the Grand total Row for 'Col C'
    Hope it helps you.
    Regards,
    Raghu

  • COMPUTE function: How to get subtotals and GRAND total together?

    I am wrtiting a report using SQL and SQL*Plus to get subtotals and a grand total. The COMPUTE function allows me to COMPUTE SUM on a group, but it only gives me subtotals. I'm interested in getting a report with the SUBTOTALS and a final GRAND TOTAL. Can this be done using SQL*Plus?
    Here is my current code that gives me subtotals:
    COMPUTE SUM LABEL subtotal OF sal ON deptno
    SELECT ename, sal, deptno
    FROM emp
    ORDER BY deptno;
    ENAME             SAL     DEPTNO
    CLARK            2450         10
    VOLLMAN          5000
    MILLER           1300
                     8750 subtotal
    SMITH             800         20
    ADAMS            1100
    FORD             3000
    SCOTT            3000
    JONES            2975
                    10875 subtotal
    ALLEN            1600         30
    BLAKE            2850
    MARTIN           1250
    JAMES             950
    TURNER           1500
    WARD             1250
                     9400 subtotalHere is the code to give one grand total:
    Column DUMMY NOPRINT
    COMPUTE SUM OF sal ON DUMMY
    BREAK ON DUMMY
    SELECT NULL DUMMY, ename, sal, deptno
    FROM emp
    ORDER BY deptno;
    ENAME             SAL     DEPTNO
    CLARK            2450              10
    VOLLMAN          5000          10
    MILLER           1300          10
    SMITH             800              20
    ADAMS            1100          20
    FORD             3000          20
    SCOTT            3000          20
    JONES            2975          20
    ALLEN            1600              30
    BLAKE            2850          30
    MARTIN           1250          30
    JAMES             950          30
    TURNER           1500          30
    WARD             1250          30
                    29025
    How can I combine both on one report?

    Massimo Ruocchio wrote:
    Do you like this?I believe OP is looking for both department totals and grand total. Frank already showed how to do it in SQL*Plus. To do it in SQL:
    SELECT  CASE GROUPING_ID(real_deptno,real_ename)
              WHEN 0 then real_ename
              WHEN 1 then 'Department ' || real_deptno || ' total'
              ELSE 'All department total'
            END ename,
            SUM(sal),
            deptno
      FROM  (
             SELECT  deptno real_deptno,
                     ename real_ename,
                     sal,
                     CASE ROW_NUMBER() OVER(PARTITION BY deptno order by ename) WHEN 1 THEN deptno end deptno
               FROM  emp
      GROUP BY GROUPING SETS((),real_deptno,(real_deptno,deptno,real_ename))
      ORDER BY real_deptno nulls last,
               real_ename nulls last
    ENAME                  SUM(SAL)     DEPTNO
    CLARK                      2450         10
    KING                       5000
    MILLER                     1300
    Department 10 total        8750
    ADAMS                      1100         20
    FORD                       3000
    JONES                      2975
    SCOTT                      3000
    SMITH                       800
    Department 20 total       10875
    ALLEN                      1600         30
    ENAME                  SUM(SAL)     DEPTNO
    BLAKE                      2850
    JAMES                       950
    MARTIN                     1250
    TURNER                     1500
    WARD                       1250
    Department 30 total        9400
    All department total      29025
    18 rows selected.
    SQL> SY.

  • Total of grand total in pivot

    Hello Guys,
    I have a situation...
    I am using Pivot View for a report (the reason being...I need the data by month in sections....)...
    I need total for each section so I used the Sum button of Rows for grand total of each section (again the reason being....if I used Sum of Sections...it will display another section as 'All sections' which is nothing but all the entries clubbed into one table.....which is not desirable in my case)..
    So, I almost have what I want..the only thing I would require is the Grand total of all the Grand totals at the bottom....
    Can anyone help me please.....I tried many ways...but couldn't get it.....

    Thanks friend....I got it...
    only problem I faced while fixing this was...The grand total formatting...I had to customize it as I didnt find a way to hide the measure grand total...
    what I mean is....after hiding the details,etc...I was left with only one row..which is the calculated column 'Grand Total',....but it was just as any other row...(i.e.,) without any formatting...default background and font...
    but when I clicked on 'Sum' for the 'Row'.....it showed me the actual Grand Total which means ...with formatting...but then....there were 2 rows now.....so I removed the 'Sum' and manually did the formatting to match with the other Grand Totals.....this was a workaround....let me know if there is any better solution...
    Thanks anyways for the solution....

  • Grand total on table with variance

    !http://img17.imageshack.us/img17/4070/resulta.jpg!
    hi, I set the column formula of variance to be: ("Current Value" - "Last Value) / "Last Value" * 100
    when I enabled the "grand total" of the table, it gives the grand total of variance = 0%.
    but actually it should be 3.3%
    how to achieve my goal.
    thank you very much!

    ("Current Value" - "Last Value) / "Last Value" * 100.00
    Change "100" to "100.00"

  • Grand Total level Discrepency

    Hi,
    I have a Pivot table view which has three measures namely Net Units, Budget Net Units, Achvd% along with channel and Account at row level.
    Here Achvd% is a calcualted column with Achvd% = (Net Units - Budget Net Units)/Budget Net Units.
    At my Grand Total level also the same Formula should apply for Total Achvd% i.e., (Total Net Units - Total Budget Net Units)/Total Budget Net Units.
    Currently it is displaying the Aggregation Level for this column as Sum.
    In the Aggregation Level Setting for any column, we have Default, Sum, Average,Min, Max,... So can this customization for this column be done at Grand Total Level.
    Can you please provide valuable inputs
    Thanks
    Sri
    Edited by: sri on Feb 2, 2011 10:54 PM

    Saichand,
    I tried as you suggested, it is working on a single request... But if we have a result set of two combined requests(union) then this option is not helpful.
    Can you suggest how to take this up while using combined requests
    Thanks,
    sri
    Edited by: sri on Feb 7, 2011 12:30 AM

  • Grand totals are not displaying...

    hi guys
    for cross tab reports grand totals (rows and columns) are not displaying.
    is there any fix to resolve.

    I have faced a similar issue in Cross tab reports.
    Try using Cell Sum/Cell Sum distinct function instead
    of the usual Sum function while calculating the grand total that function is working for Grand Total at bottom but not working for Grand Total on right [i]

  • Get Grand total of the subtotals

    Hi,
    I am devoloping a report which pulls the expense lines for each project.I am displaying the fte count at each line.As it'll be same for a particular project,all the lines for that particular project will show the same FTE count.I am grouping the
    lines by Project No in Desktop edition.Now I want the total fte count which is the sum of the fte counts at each grouped level.So I cant use the total as it'll give the grand total of all the line entries.But I am not finding any option for this kind of total.(Total of the subtotals)
    Pls give me a solution ASAP

    Hi,
    I am devoloping a report which pulls the expense lines for each project.I am displaying the fte count at each line.As it'll be same for a particular project,all the lines for that particular project will show the same FTE count.I am grouping the
    lines by Project No in Desktop edition.Now I want the total fte count which is the sum of the fte counts at each grouped level.So I cant use the total as it'll give the grand total of all the line entries.But I am not finding any option for this kind of total.(Total of the subtotals)
    Pls give me a solution ASAP

  • Presentation Hierarchy Grand Total Values

    Hi,
    We have the following scenario,
    Hierarchy Product A is created for Dimension Product A
    Hierarchy Product B is created for Dimention Product B
    Fact Product Measures is joined to Store Dimension , Dimension Product A, Dimention Product B and Fiscal Calendar
    Dimension Product A contains subset of Products that are existing at Fact
    Dimention Product B contains subset of Products that are existing at Fact
    and some products can exists both at Dimension Product A and Dimension Product B
    The issue we are facing is, when ever report is created using One of the Product Hierarchy and Fact. Product Sales (default aggregation is sum),
    the grand total level is showing sum of all Product Sales. It is not limiting to Products that are in Product Hierarchy selected in the report.
    But the sub levels are limiting based on selected Product Hierarchy which is causing not matching the roll up amount to grand total.
    Is it possible to limit the grand total level value of Presentation Hierarchy based on selected Product Hierarchy.
    Does anyone face similar issue.
    Thanks in Advance

    is your summary and detail reports hitting different facts, like summary hitting aggregate and detail report hitting it's corresponding detail level fact..?
    if then,
    From Front-end:
    Fix the filter values in detail report that are passing from master report then try delete each columns then check the grand total. If you found your values is matching by deleting particular column then you need to investigate what is the issue around with that dimension table..
    From Database side:
    1. check first aggregate table has proper aggregate data of it's detail..
    2. Take the detail report obiee generated query and try to comment each dimension table and it's corresponding joins to the facts, (before, this delete all the dimensional columns and other measures from select statement and put only that measure where you are getting wrong value, so that you need not to comment all the select and group by columns which saves your time.. ). Need to check by commenting each dimensional wid and it's table from clause, if you found that values is matching then there is some problem with wid columns data population in your ETL.
    Is that BI-Apps project?
    btw, whtz ur name?

  • OBIEE 11g Grand total issue

    Hello,
    I have one requirement where I want to show the data as follows
    Type          Metric          Values
    Type1          units          100
              Days          50
              % Calc     10%
    Type2           units          100
              Days          50
              % Calc     10%
    Type3          units          100
              Days          50
              % Calc          10%
    Total units     300
    Total Days     150
    Total % Calc 30%
    If I take grand total of row in pivot table, I am not able to show Total units, Total Days and Total % Calc values in Grand Total because by default, same grand total name appears.
    I want to give different grand total names and percentage sign should appear in grand total.
    Please let me know if u need any more information.
    Thanks.

    Try to recreate the report. Just in case make sure that you dont have null values in that metric or try with ifnull(col,0)
    Check this bug too BUG:9871470
    Keep update

  • Grand total values are not matching with Detail report

    Report has grand totals and when I drill to the detail report, grand total values are NOT matching with parent report totals, I did some analysis but I'm clueless on this issue.
    Please provide your thoughts and insight on this issue..
    Thanks

    is your summary and detail reports hitting different facts, like summary hitting aggregate and detail report hitting it's corresponding detail level fact..?
    if then,
    From Front-end:
    Fix the filter values in detail report that are passing from master report then try delete each columns then check the grand total. If you found your values is matching by deleting particular column then you need to investigate what is the issue around with that dimension table..
    From Database side:
    1. check first aggregate table has proper aggregate data of it's detail..
    2. Take the detail report obiee generated query and try to comment each dimension table and it's corresponding joins to the facts, (before, this delete all the dimensional columns and other measures from select statement and put only that measure where you are getting wrong value, so that you need not to comment all the select and group by columns which saves your time.. ). Need to check by commenting each dimensional wid and it's table from clause, if you found that values is matching then there is some problem with wid columns data population in your ETL.
    Is that BI-Apps project?
    btw, whtz ur name?

  • Reg : Grand Total in OBIEE

    hi all,
    I have two measure columns and i performed grand total on that columns .
    Here, I want grand total only for one measure column (I dont want to use default aggregatio rule as none).
    Any formatting options available(for eg: fill the same color for the measure as well as value for the particular column Grand Total)
    Can u help on this?
    Edited by: udeffcv on Apr 5, 2010 12:24 AM

    If you are using Pivot table.,
    try placing the measure cols(for which grand total is not needed) in the "Rows" section of the pivot table.
    Regards,
    Raghu

  • Grand total showing wrong results

    Hello,
    I am having one prblem,using obiee 11g.
    Have a pivot table with 3 columns, one is month and other are showing numbers.
    For month we show the 2 number columns
    when i click grand total its showing the wrong total for the second number column.
    I really don't understand why its happening?
    Any help?
    Thanks

    Hi,
    Set Aggregation Rule as Server Complex Aggregate may solve your problem, ie goto
    Column -> Edit Formula -> Aggregation Rule -> Server Complex Aggregate
    Thanks,
    Balaa...

Maybe you are looking for

  • YTD, MTD, Prior Year, Prior Month calculations in SAP BW Universe

    I am finding the SAP BW based universe a totally different animal so far and my question comes from my inexperience in this domain. In a normal universe, one can use CASE Statement and Calendar or Time table to help do these calculations. Since BW ba

  • How can I export/save my iphoto'11 photo book pages as actual images of the pages (jpeg), not PDF?

    I have 'printed' the book as a PDF, but would like to get a jpeg version of each actual page (not the individual photos). So far, I have tried 'exporting', but that gives me each pic individually, sharing-same thing. My goal is to upload the finished

  • Replace  between [ and ]

    Hi can someone give me a simple example of how to replace all characrters between '[' and ']' with one hardcoded string , eg schema name. I know how to do it with instr but looing for something straightforward with reg exp probably Edited by: Keith J

  • Sky go funktioniert nicht

    Hallo, mein sky go funktioniert nur beim imac nicht - im Ipad klappt alles einwandfrei - bei Sky sagt man mir, dass lege wohl an der Software des imac - kann mir jemand erklären, was ich tun muss?

  • StandBy database Create/Export Issue

    We have database ABC and standby database ABCSTD and they are working properly. (Archives are properly applied), They were created from the database ABC_OLD. Issue is that the ABC_OLD database has some more changes and users continued to work on that