SUM( ) versus Aggregation SUM

When creating a new logical column for a fact table, I can define it with an expression like SUM (column A - columnB) with aggregation rule None - column A and B being pointed to physical columns.
On the other hand I can use an expression (column A - columnB) with aggregation rule SUM in the logical column.
I understand that we can use either way....
Pls. am I correct ?
Txs.
Antonio

Hi Lambo,
I can use an expression (column A - columnB) with aggregation rule SUM in the logical column. --- You can apply this way.
Another method:-
Open your report and add new column in your report then click FX then apply below syntax.
sum(column A-column B). it will come out as you experted result.
Award points it is useful.
Thanks,
satya

Similar Messages

  • Deletion of Total(Aggregated Sum) rows in planning book

    I want to get rid of 'Total(Aggregated Sum)' rows in planning book tables.
    'Total' line is useful but too many lines are uncomfortable for planners, so we're searching for the method not to use it.
    If you know how to configure or use macro for it, please let me know.
    Thank you,
    HyeRee

    Hi,
    I can delete totals, but I can´t delete subtotals.
    Macro Delete Totals
    IF
    New condition
       PLOBS_FOR_LEVEL( ACT_LEVEL ) = 1
    Step 1 iterations
       ROW Ratio 1
          ROW_VISIBLE( 0 )
       ROW Ratio 2
          ROW_VISIBLE( 0 )
       ROW Ratio n
          ROW_VISIBLE( 0 )
    ENDIF
    This macros works ok to deleting row totals.
    Raúl.

  • Calculations with Sum Distinct Aggregations

    Hi,
    I got a problem. I use in one of my analysis a Pivot Table. One of my measures which I sum up has multiple entries in my tables. So I decided to use a Sum Distinct aggregation. The Sum Distinct aggregation works perfect. But when I want to do basic calculations with the measure I get wrong results. It seems that in the calculation the aggregation is just a SUM and not a Sum Distinct. In the calculation I subtract the measure from a constant. But I only get wrong result with the redundant entries.
    Pivot table:
    Name --- Days available --- Days worked (measure)--- Days left (= Days available minus Days worked)
    Mr. A --- 60 --- 5 ---- 55
    Mr. A --- 60 --- 10 --- 50
    Mr. A --- 60 --- 35 --- 25
    ---------- Sum ---- 50 --- -45 (wrong result)
    Is there a solution to this problem?
    thx
    Edited by: Backlit on 31.07.2011 11:29

    Hi,
    and thx for the quick answer. But unfortunately the Server Complex Aggregate aggregation doesn't solve my problem. I also think I didn't express my self clear enough.
    My problem is, that I have the same tuple multiple times in my database table. When I sum this data up - I get wrong results. To avoid this I used the SUM DISTINCT aggregation. This worked very fine. But now I'm facing an other problem. I have to perform a simple subtraction.
    I have a fixed non measure value. I have to subtract the Sum Distinct measure from this fix value for a specified time periode.
    it looks like this:
    Pivot table
    Name --- Days available(non measure) --- Work date --- Days worked (SUM) measure --- Days worked SUM(Distinct) measure
    Mr.A --- 40 --- 1.5 --- 6 --- 3
    Mr.A --- 40 --- 1.5 --- 6 --- 3
    Mr.A --- 40 --- 2.5 --- 6 --- 3
    Mr.A --- 40 --- 3.5 --- 6 --- 3
    Mr.A --- 40 --- 3.5 --- 6 --- 3
    Mr.A --- 40 --- 3.5 --- 6 --- 3
    SUM ---- 40 --- .... ---- 6 --- 3 -> Days left: 34 (wrong result - should be 37)
    I get the right result - but when I now try to calculate "Days available - Days worked SUM(Distinct)" I get the same results like I would do the calculation with
    "Days available - Days worked SUM".
    And is there a way to hide the multiple values in Days worked?
    thx

  • Sum of a sum when using Top N in the Group Sort Expert

    Hi All,
    I have a small problem I can't quite seem to work out.
    I have a report where each line is for a particular Product, and is a summation of the Sales for that Product over several Locations. When you click on the line, it shows the breakdown of Sales over each Location.
    I use the Group Sort Expert to display the Top N results, where the 'N" is set in a formula to a parameter passed in to the report, so the user can select the top 5,10,50 etc. Products across all Locations.
    At the bottom of the report, I want to have a sum of a column of Sales $. I need that sum to only be a sum of the Top N records selected.
    Since each line is a summation of the all the products for the Locations, what I need is a sum of that sum for the Top N, but Crystal will not let you add the sum of a sum, so I'm not sure how to accomplish this.
    If I just do a sum of the underlying values I get a total for all the Products, regardless of the Top N.
    Hope that makes some sense !
    Many Thanks
    Paul

    Hi Sastry,
    I tried your suggestion, thanks, but I don't think it's the answer. For a start Crystal will not let me do that, it pops up a message box when I try to run the report "A running total cannot refer to a print time formula. Details: Record Number". I also added the record number field next to the lines in the report to see what the result would be, and I don't think it would work anyway.
    Here is an example using Units sold:
    Product Name--LocationUnits Sold--Record Number
    Product A -<All Stores>----8
    Store A--1--
    1
    Store B--3--
    2
    Store C--4--
    3
    Product B--<All Stores>--3      
    Store A--2--
    4
    Store B--1--
    5
    Product C--<All Stores>--
    1
    Store A--1--
    6
    Note that only the bold lines are shown in the report,. If you click on the bold line, then the breakdown of the stores is shown. For the above example, I am showing the Top 2 units across all stores (so Product C is not shown at all), but there are actually 5 records, so if I used a formula where RecordNumber <=N, where in this case N=2, I would get a total units sold of 1 + 3 (records 1 and 2) which is incorrect.
    I will have more of a think on this and see if I can find a solution, in the mean time, any other suggestions ? Is there some wya of checking if the line is visible maybe ?
    Thanks for your time !
    Paul

  • What is the difference between   nvl(sum (field), 0) & sum(nvl (field,0)) ?

    What is the difference between nvl(sum (field), 0) & sum(nvl (field,0)) ?
    For the below table data i don't see any different in results
    CREATE TABLE FRUITS
    TYPE VARCHAR2(10 BYTE),
    VARIETY VARCHAR2(10 BYTE),
    PRICE NUMBER(18,2)
    TYPE     VARIETY          PRICE
    apple     gala          2.79
    apple     fuji          0.24
    apple     limbertwig     2.87
    orange     valencia     3.59
    orange     navel          9.36
    pear     bradford     7.77
    pear     bartlett     7.77
    cherry     bing          2.55
    cherry     chelan          6.33
    pear     bradford     
         navel          6.39
    select variety, nvl(sum(price),0)
    from fruits
    group by variety;
    VARIETY     NVL(SUM(PRICE),0)
    limbertwig     2.87
    bartlett     7.77
    bing     2.55
    marathon     0
    gala     2.79
    fuji     0.24
    navel     15.75
    bradford     7.77
    chelan     6.33
    valencia     3.59
    select variety, sum(nvl(price,0))
    from fruits
    group by variety;
    VARIETY     SUM(NVL(PRICE,0))
    limbertwig     2.87
    bartlett     7.77
    bing     2.55
    marathon     0
    gala     2.79
    fuji     0.24
    navel     15.75
    bradford     7.77
    chelan     6.33
    valencia     3.59
    no difference in output.
    what is the difference?
    Thanks in advance

    Do you see the difference now?
    PRAZY@11gR1> create table testing(field number);
    Table created.
    Elapsed: 00:00:00.10
    PRAZY@11gR1> insert into testing select null from dual connect by level<=5;
    5 rows created.
    Elapsed: 00:00:00.00
    PRAZY@11gR1> select * from testing;
         FIELD
    Elapsed: 00:00:00.01
    PRAZY@11gR1> select sum(nvl(field,1)) from testing;
    SUM(NVL(FIELD,1))
                    5
    Elapsed: 00:00:00.00
    PRAZY@11gR1> select nvl(sum(field),1) from testing;
    NVL(SUM(FIELD),1)
                    1
    Elapsed: 00:00:00.00In the former, we are substituting 1 to null value and summing-up. hence we got 5. in the later, we are summing-up the null, which is null and substituting 1 if the result is null. so we got 1.
    Regards,
    Prazy

  • "Select sum(field)" not summing

    I have a PLSQL statement like:
    select sum(field1) sum1,
    sum (field2) sum2
    into v_sum1,
    v_sum2
    where something = somethingElse;
    How come my variable are being assigne a single row's (the first) field1 and field2 values rather than the actual sums?
    If I do a SQLPLUS version of this (without the "into" part), I get the correct sums returned in a single row.
    Thanks,

    I just tried your query and it should work if you only want a sum for a specific where clause. For example one employee's salary given the employee's id. If you want a list of salaries for every employee in a specific department, you need to put this into a cursor and loop through it.
    This will look at all the rows based on the where statement and sum them all up. The reason it works in SQL*PLUS is that an implicit cursor is used (loops through automatically).
    ex:
    DECLARE
    CURSOR C_SUM is
    select ename,
    sum(sal) sum1,
    sum(comm)sum2
    from emp
    where deptno = 30;
    BEGIN
    FOR R_SUM IN C_SUM
    LOOP
    DBMS_OUTPUT.PUT_LINE(r_sum.ename ||' '||
    r_sum.sum1 ||' '||
    r_sum.sum2);
    END LOOP;
    END;
    Make sure if you use DBMS_OUTPUT you have serveroutput on. Hope this helps. If it doesnt, post the actual code you are having problems with.

  • Measure SUM vs. SUM(measure)

    Problem solved, it was another reason!
    Hello,
    I have a problem I don't understand. What is the different between using "measure SUM" and "SUM(measure)"? If I use it alone it will both give me correct results, if I use it in another formula the results are different:
    sum(m1) = 2
    sum(m2) = 1
    sum(m1) - sum(m2) = 0 <-- that's wrong
    m1 SUM = 2
    m2 SUM = 1
    m1 SUM - m2 SUM = 1 <-- that's correct, but what is different?
    Thank you
    Tobias
    Message was edited by:
    toki

    It was a strange kind of problem and unfortunately i cannot regenerate it well.
    First there was a calcalation (sum(m1) - sum(m2)) which was accumulated. The sum did not return exaclty the correct value. Then, i tried several formulas, sums, drills I cannot remember all combinations and changed the formula to m1 SUM - m2 SUM and it worked fine. Then, after my posting here I rubbed my eyes as I saw that m1 SUM - m2 SUM now did also returned the wrong result.
    I cannot explain this behavior, however, the lost values were caused by NULL-values in some rows (e.g. 5 - NULL = NULL, it should by 5 - 0 = 5), so I added a CASE WHEN m2 IS NULL THEN 0 ELSE m2 END.
    Tobias

  • Data error - Double value of Sum row Aggregation

    Hello,
    I've recently created a new UNX universe based of SQL server query wich brings me determined values for payments and debts, when check the value on my XLS file wich is the main data source for the SQL DB, a single row is for 66,207.70 but on the universe when i check the values it doubles it.
    Here are four sets of pictures showing the value of a client PGE/ACRE when it's under AVG aggregation and when it's under SUM aggregation.
    Can someone help me identify the reason and how to fix it?

    Hi Marvin,
    In report level you getting double value so you can unchecked avoid duplicate row.
    Thank you
    Mustafa

  • Aggregation / Summing problems

    Hello guys!
    I am currently working on a tricky statement and don't know how to achieve a conditional summing.
    I have the following statement:
    SELECT decode(n.BA_KATNEW, 'hG','Heimische Gesellschaftsfremde','xi','Nebenbaumart + B + S', 'P','Pionierbaumart', 'H', 'Hauptbaumart', 'nG', 'Nicht heimische Gesellschaftsfremde') BA_FINALNAME, decode(n.BA_KATNEW, 'hG','hG','xi','N + B + S', 'P', 'P', 'H', 'H','nG','nG') BA_FINAL, n.AGGRESULT FROM (
    SELECT ba_kat, ba_katnew, Calc, (sum(m.Calc) over (partition by ba_katnew)) AGGRESULT from (
    SELECT
    decode(ba_kat,'P','P','B','xi','N','xi','S','xi','hG','hG','H','H','nG','nG') ba_katnew, z.ba_lang, z.ba_kat, z.BA_GRUPPE, z.STR_LRT_MAIN, z.Bestand, z.Zaehlfaktor, z.Ergebnis, z.Prozent, sum(z.Ergebnis) over (partition by z.STR_LRT_MAIN) TOTAL,
    round((sum(z.PROZENT) over (partition by z.ba_kat)),2) CALC
    from
    (select
    b.ba_lang,
    x.ba_kat,
    p.STR_LRT_MAIN,
    sum(v.DBL_Bestand) Bestand,
    :P2010_ZAEHLFAKTOR_BESTAND Zaehlfaktor,
    sum(v.DBL_Bestand) * :P2010_ZAEHLFAKTOR_BESTAND Ergebnis,
    round(SUM(v.DBL_Bestand) * 100 / (SELECT SUM(v2.DBL_Bestand)
                                       FROM   VT_TBL_BESTAND     v2,
                                              VT_PUNKTDATEN_JOIN p2
                                       WHERE  (p2.cnt_gebiet = :P2010_cnt_GEBIET)
                                       AND    (v2.LNG_INV_PT_ID = p2.INV_PT_ID_SUB)
                                       AND    (p2.str_lrt_main = :p2010_str_lrt)
                                       AND    (p2.int_status_sub = 3)),2) AS Prozent,
    decode(b.BA_GRUPPE,1,'Ba-Grp. 1',2,'Ba-Grp. 2',3,'Ba-Grp 3',4,'Ba-Grp. 4',5,'Ba-Grp. 5',6,'Ba-Grp. 6',7,'Ba-Grp. 7',8,'Ba-Grp. 8') BA_GRUPPE
    from
    VT_TBL_BESTAND v,
    VT_PUNKTDATEN_JOIN p,
    vt_tbl_baumart b,
    VT_TBL_MATRIX x
    where
    (p.cnt_gebiet = :P2010_cnt_GEBIET)
    and (v.lng_baumart = b.cnt_baumart)
    and (v.LNG_INV_PT_ID = p.INV_PT_ID_SUB)
    and (p.str_lrt_main = :p2010_str_lrt)
    and (p.int_status_sub = 3)
    and (x.LRT_CLASS=:p2010_str_lrt)
    AND (x.LNG_BAUMART=v.LNG_BAUMART)
    group by
    b.BA_LANG,
    x.BA_KAT,
    BA_GRUPPE,
    p.STR_LRT_MAIN) z) m group by ba_kat, ba_katnew, Calc) n GROUP BY BA_KATNEW, AGGRESULTIt produces an output such as:
    BA_FINALNAME BA_FINAL AGGRESULT
    "Heimische Gesellschaftsfremde"     "hG"     "3,76"
    "Nebenbaumart + B + S"     "N + B + S"     "7,3"
    "Pionierbaumart"     "P"     " 0,42"
    "Hauptbaumart"      "H"     "88,54"
    The final demand on this query is to sum AGGRESULT for the following combinations in one column:
    BA_FINAL= H+N
    BA_FINAL= H+N+P
    BA_FINAL= N+P
    and returning the AGGRESULT values for all other values in BA_FINAL as they are.
    Is this even possible? I know my statement is a little confusing but I hope you're not confused and give me a chance!
    I'd appreciate your help, since I don't know how to build sums over groups in one column.
    Regards,
    Sebastian
    Edited by: skahlert on 15.10.2009 15:22

    Good morning Frank!
    Well, the query is working thanks to your help. However, I wanted to assign some strings to the new categorized tree species i.e. 'H', 'N+B+S' etc.
    Hence I wanted to use the decode function once more but ultimately receive a group by expression error. I actually thought it should work like that? Can you please have a look at it again and tell me what I did wrong!?
    By the way, thanks for teaching me how to write the code! Really appreciate it!
    The line is her:
    decode(x.ba_final,'N+B+S / H / P', 'Haupt- + Neben- + Pionierbaumart','N+B+S / H', 'Haupt- + Nebenbaumart incl. B+S','N / P','Nadelbaumarten² mit > 50% Anteil', 'H', 'Hauptbaumart', 'nG', 'Nicht heimische Gesellschaftsfremde', 'hG', 'Heimische Gesellschaftsfremde') ba_finalnamewhile the full code looks like:
    WITH   special_grp            AS
         SELECT 'H' AS ba_final, 'N+B+S / H / P' AS grp     FROM dual     UNION ALL
         SELECT 'N + B + S', 'N+B+S / H / P'             FROM dual     UNION ALL
         SELECT 'P', 'N+B+S / H / P'             FROM dual     UNION ALL
         SELECT 'H', 'N+B+S / H'             FROM dual     UNION ALL
         SELECT 'N + B + S', 'N+B+S / H'             FROM dual     UNION ALL
         SELECT 'N', 'N / P'                  FROM dual     UNION ALL
         SELECT 'P', 'N / P'                  FROM dual UNION ALL
            SELECT 'H', 'H'                          FROM dual UNION ALL
            SELECT 'nG', 'nG'                  FROM dual UNION ALL
            SELECT 'hG', 'hG'                  FROM dual
    SELECT       NVL ( s.grp
               , x.ba_final
               )               AS ba_final
    ,       SUM (x.aggresult)     AS aggresult, decode(x.ba_final,'N+B+S / H / P', 'Haupt- + Neben- + Pionierbaumart','N+B+S / H', 'Haupt- + Nebenbaumart incl. B+S','N / P','Nadelbaumarten² mit > 50% Anteil', 'H', 'Hauptbaumart', 'nG', 'Nicht heimische Gesellschaftsfremde', 'hG', 'Heimische Gesellschaftsfremde') ba_finalname
    FROM                 (SELECT decode(n.BA_KATNEW, 'hG','Heimische Gesellschaftsfremde','xi','Nebenbaumart + B + S', 'P','Pionierbaumart', 'H', 'Hauptbaumart', 'nG', 'Nicht heimische Gesellschaftsfremde') BA_FINALNAME, decode(n.BA_KATNEW, 'hG','hG','xi','N + B + S', 'P', 'P', 'H', 'H','nG','nG') BA_FINAL, n.AGGRESULT FROM (
    SELECT ba_kat, ba_katnew, Calc, (sum(m.Calc) over (partition by ba_katnew)) AGGRESULT from (
    SELECT
    decode(ba_kat,'P','P','B','xi','N','xi','S','xi','hG','hG','H','H','nG','nG') ba_katnew, z.ba_lang, z.ba_kat, z.BA_GRUPPE, z.STR_LRT_MAIN, z.Bestand, z.Zaehlfaktor, z.Ergebnis, z.Prozent, sum(z.Ergebnis) over (partition by z.STR_LRT_MAIN) TOTAL,
    (sum(z.PROZENT) over (partition by z.ba_kat)) CALC
    from
    (select
    b.ba_lang,
    x.ba_kat,
    p.STR_LRT_MAIN,
    sum(v.DBL_Bestand) Bestand,
    :P2010_ZAEHLFAKTOR_BESTAND Zaehlfaktor,
    sum(v.DBL_Bestand) * :P2010_ZAEHLFAKTOR_BESTAND Ergebnis,
    SUM(v.DBL_Bestand) * 100 / (SELECT SUM(v2.DBL_Bestand)
                                       FROM   VT_TBL_BESTAND     v2,
                                              VT_PUNKTDATEN_JOIN p2
                                       WHERE  (p2.cnt_gebiet = :P2010_cnt_GEBIET)
                                       AND    (v2.LNG_INV_PT_ID = p2.INV_PT_ID_SUB)
                                       AND    (p2.str_lrt_main = :p2010_str_lrt)
                                       AND    (p2.int_status_sub = 3)) AS Prozent,
    decode(b.BA_GRUPPE,1,'Ba-Grp. 1',2,'Ba-Grp. 2',3,'Ba-Grp 3',4,'Ba-Grp. 4',5,'Ba-Grp. 5',6,'Ba-Grp. 6',7,'Ba-Grp. 7',8,'Ba-Grp. 8') BA_GRUPPE
    from
    VT_TBL_BESTAND v,
    VT_PUNKTDATEN_JOIN p,
    vt_tbl_baumart b,
    VT_TBL_MATRIX x
    where
    (p.cnt_gebiet = :P2010_cnt_GEBIET)
    and (v.lng_baumart = b.cnt_baumart)
    and (v.LNG_INV_PT_ID = p.INV_PT_ID_SUB)
    and (p.str_lrt_main = :p2010_str_lrt)
    and (p.int_status_sub = 3)
    and (x.LRT_CLASS=:p2010_str_lrt)
    AND (x.LNG_BAUMART=v.LNG_BAUMART)
    group by
    b.BA_LANG,
    x.BA_KAT,
    BA_GRUPPE,
    p.STR_LRT_MAIN) z) m group by ba_kat, ba_katnew, Calc) n GROUP BY BA_KATNEW, AGGRESULT
    )     x
    LEFT OUTER JOIN      special_grp     s     ON     s.ba_final     = x.ba_final
    GROUP BY  NVL ( s.grp
               , x.ba_final
    ORDER BY  UPPER (ba_final)Regards,
    Sebastian

  • Problem aggregating sums in a while loop

    I'm relatively new to java. In my latest project, one part of the project is to translate this equation:
    [http://img.photobucket.com/albums/v281/molotov001/rt01.jpg]
    into java.
    Retaining what little knowledge I have of Calculus, this basically means that I should start with i=0, run through that function and increase i by 1 until it reaches a final number yearsWorked-1, all the while adding the functions with respect to different values of i.
    This is what I have so far
    int i = 0;
    double aime = (income * Math.pow(1.02, i) * Math.pow(1.04, (year - incYear - i)))/420;
              while (i <= (yearsWorked-1))
                   ++i;
                   double aime1 = (income * Math.pow(1.02, i) * Math.pow(1.04, (year - incYear - i)))/420;
                   aime = aime + aime1;
              }I know this is wrong because it outputs a number that is incorrect, but not by much. Also assume that income, incYear, yearsWorked and year are already defined doubles.
    Any help you might be able to offer is greatly appreciated.

    {color:#000080}Use an integer type like int or long for yearsWorked. When using double, yearsWorked - 1 may not be the exact value you expected.
    Why do you need a double value for a variable that you compare integrally anyhow?
    db{color}

  • Reports sum don't sum as they should

    Hi,
    I created a report where it displays, in order: COST CENTER, PROJECT, EMPLOYEE, JAN, FEB... DEC
    Then I check on sum for JAN, FEB.... DEC under columns attributes.
    Then I have a break for the first and second columns (COST CENTER, PROJECT), so it will give me a sum for project total, and a sum for cost center total.
    The thing is that there is a case that the project is the same, but in different cost center, what the report is doing is that since the project is the same, even though the cost center is different, it's returning a sum for project total combining 2 different cost centers. This should not happen since cost center is highest in the hierarchy so even 2 different cost centers with the same projects, it should return a sum of the projects separtely, since although the same project, they belong to 2 different cost centers.
    How can I fix this?
    Thanks,

    I have no idea if this is "good" SQL or not, I played with it until it worked. :-)
    Going through the SQL a line at a time:
    select decode(grouping_id(cost_center)+grouping_id(project)+grouping_id(amount),3, 'Report Total:',2,'Cost Center '||cost_center||' Subtotal:',1,'Project '||project||' Subtotal:',0,null) tag,grouping_id(item) is set to 1 when that item level is being totaled, 0 otherwise. So this is basically a case statement. Column 1 is the 'Tag' field, which is just a label and not in the database.
    If the sum of the grouping_id values is 3, then select the text 'Report Total:' for column 1
    Else if the sum is 2, select 'Cost Center ' concatenated with the value of the current cost center, concatenated with 'Subtotal:' in for column 1
    Else if the sum is 1, you're subtotalling the project, so select 'Project' concatenated with the project value and 'Subtotal:' for the 'Tag' column.
    Otherwise, display null.
    This brings up a feature I'd like to see in ApEx: It would be nice to be able to display not only the column headers in the break row, but also the value/name of the item currently being totaled. Another nice feature would be if I could get around having to use this 'Tag' field and, instead, have column 1 span several TD cells so that I could get the label over next to the subtotal values instead of in column 1.
    On to line/column 2. Similar to before, this is a case statement, determining what goes in the cost_center field:
    decode(grouping_id(cost_center)+grouping_id(project)+grouping_id(amount),0,cost_center,null) cost_center, If the sum of all three grouping ids is 0 (not rolling up or subtotalling), show cost_center, otherwise show null.
    The next line, for project, works the same way.
    decode(grouping_id(cost_center)+grouping_id(project)+grouping_id(amount),0,project,null) project, If the sum of all three grouping ids is 0 (not rolling up or subtotalling), show project, otherwise, show null.
    The next field, Amount, is a little tricky:
    decode(sum(amount),amount,amount,sum(amount)) amount, Again, take it as a case statement (or if-then-elseif)...
    if the sum(amount) is the same as amount (displaying regular row), show the amount, otherwise, show the sum(amount).
    Why do this? Because I don't want two columns for amount and sum(amount). I want the sum to display in the Amount field on a report row. I suppose I could have summed up the grouping_id values as before, eh?
    In the report attributes, I suppress the display of the last field, sum(amount).
    sum(amount) The final bit defines the grouping sets:
    from breakreport group by grouping sets((cost_center, project, amount),(cost_center, project), (cost_center),());This says: Aggregate on amount, then project, then cost center, then give an overall total.
    Google for "grouping_id oracle" and you'll find a bunch of very nice links to Ask Tom and other places that discuss grouping.

  • Returning total sum plus pivoted sums in same result set

    I want to return a result set in the following format:
    YEARMONTH Total ModelA ModelB ModelC
    200101    0     0      0      0
    200102    10    5      5      0
    200103    8     2      2      4where the total is the sum of the hours for all model types grouped by yearmonth, and the individual model columns are the sum of hours per model type grouped by yearmonth. I can get the correct results using the following query with nested selects:
            select distinct yearmonth,
         sum(a.hours) as Total,
         (select sum(b.hours) from model_hours b
             where model = 'ModelA' and a.yearmonth = b.yearmonth) as ModelA,
            (select sum(b.hours) from model_hours b
             where model = 'ModelB' and a.yearmonth = b.yearmonth) as ModelB,
            (select sum(b.hours) from model_hours b
             where model = 'ModelC' and a.yearmonth = b.yearmonth) as ModelC
        from model_hours a
        group by yearmonth
        order by yearmonthI was curious to try using the pivot function in Oracle 11 to achieve the same results, and am able to get all the results EXCEPT the total hours using the following query:
        select * from (
             select yearmonth, hours, model
             from model_hours a
        pivot
             sum(hours)
             for model in ('ModelA', 'ModelB', 'ModelC')
        order by yearmonthwhich returns this result:
    YEARMONTH  ModelA ModelB ModelC
    200101     0      0      0
    200102     5      5      0
    200103     2      2      4I have not been able to figure out how to also get the sum of the hours for all models, grouped by yearmonth, into this resultset. Is it possible? And if so, would it be likely to be more efficient than the nested selects? This particular table has some 200K rows right now.

    Hi,
    923402 wrote:
    Frank, thank you so much. I added a bunch of nvl() functions and it works now. Didn't have a chance to try it with the other answer but it looks like it would be similar.
    I'm still curious as to whether doing it this way is more efficient than my original query, using nested selects.Definitely! Scalar sub-queries, like you did in your first message, will require multiple passes through the table. SELECT ... PIVOT only requires one.
    Here's another way that should be as efficient as SELECT ... PIVOT:
    SELECT       yearmonth
    ,       SUM (hours)                                   AS total
    ,       NVL (SUM (CASE WHEN model = 'ModelA' THEN hours END), 0)     AS modela
    ,       NVL (SUM (CASE WHEN model = 'ModelB' THEN hours END), 0)     AS modelb
    ,       NVL (SUM (CASE WHEN model = 'ModelC' THEN hours END), 0)     AS modelc
    FROM       model_hours
    GROUP BY  yearmonth
    ORDER BY  yearmonth
    ;The NVLs are only necessary for display; you don't need them to get the correct total.
    I don't have access to a SQL efficiency testing program; otherwise, I'd test it myself; if you don't think you can answer I'll just give it to our overworked DBA. Ask your DBA if you can use EXPLAIN PLAN.

  • Discoverer  report does not sum up the column

    Hi All,
    I am running the discoverer report from discoverer desktop and was
    trying to use the sum function to sum the total amount of the report.
    The sum function does not work and it only display Cell
    Sum: (blank) with no actual data.
    When i checked the report details some columns are calculated based on the columns which i want to sum up.
    Any ideas please share with me
    Thanks in advance.

    b) What is the difference between sum and cell sum? Well, I certainly won't claim to be a Discoverer guru. From what little I have seen, the practical result is not any difference really between the two. SUM of a calculated row is adding up the calculation to the total. Whereas cell sum is like adding up the individual values behind the calculation you see. The distinction makes more sense when you have SUM DISTINCT and CELL SUM DISTINCT being involved. Then you will see a difference in the calculated total. But for SUM and CELL SUM itself, I have not seen any difference between the two, but I am still pretty new to Discoverer.
    e) Aggregate field from a folder. Well, this may be one where you have to play around with your own data to understand. Let me try to give you a simple example. Let's say you have a sales table with 100 rows. You have sales data for 5 cities, and each city has 20 rows of sales history. If you pick Sales Dollars Detail and City Name for your workbook and run, you will get 100 rows in your result (complete detail listing). So that is what happens with no aggregation. Now, instead of doing Sales Dollars Detail, you pick Sales Dollars Sum (the same thing as saying SUM(Sales Dollars) in an SQL statement). Run the workbook. You will now get 5 rows of data, instead of 100 rows of data. You will get one row for each city. If you look at the SQL that Discoverer generates, you will see that it has now done a GROUP BY in the SQL statement. Notice I have not said anything about DISTINCT (just trying to keep things simple).
    Now, lets say you do a workbook for City, Part Number, and Sales Dollars Sum. Run the workbook. You get a summarized result (say maybe 10 rows of summary data this time). If you look at the Discoverer SQL, the GROUP BY is now by city and part number, automatically doing that because you picked the SUM version of sales dollars.
    Now lets say you add Sales Units Detail to the workbook. Discoverer will give you a warning message that you are have both an aggregate and a non-aggregate and that you may end up with unpredictable results. Run the workbook. You will be back to 100 rows, because you specified sales units in detail.
    Most of the time I do not want to see detail rows in a workbook. So most of the time I am picking the SUM aggregate for an amount item.
    Hope this explains things a bit. Sounds like maybe you need to take the Discoverer Create Queries and Reports class. Would help you understand these things better. Good luck.
    John Dickey

  • Discoverer plus  report does not sum up the column

    Hi All,
    I am running the discoverer report from discoverer plus (web version) and was
    trying to use the sum function to sum the total amount of the report.
    The sum function does not work and it only display Cell
    Sum: (blank) with no actual data.
    When i checked the report details some columns are calculated based on the columns which i want to sum up.
    My query uses CASE function to calculate one of the columns.
    I changed the aggregation behavior setting to "Show the sum of the calculated values from the contributing cells "
    then also i'm not able see the totals.
    Any ideas please share with me.
    Thanks in advance,

    Hard to answer your question without seeing what you are trying to do. Issues like this are often better reported to Oracle support, where they can get a web sesison going and be able to see what you see on your computer. Would be helpful to illustrate exactly what your detail looks like and how you are trying to create your sum. There could be several possible issues that could cause your problem, so all I can do is speculate some. Are you trying to sum one column, or are you creating multiple totals (for multiple columns)? Do you have any rows in the column with a NULL value? NULL values will be a problem when trying to sum up a column. You would need to convert the NUll value to something else, probably a zero. That would be the first thing I would look at. Hope that helps a little bit.
    John Dickey

  • In OBIEE Report Grand Total instead of Average(Average)  use Sum(Avg)?

    Hi All,
    In OBIEE Report Grand Total average always shows Average of average (Default) "avg(avg)" , can i overwrite this functionality to sum of average "sum(avg)".
    Thanks in advance
    Regards
    Kandasamy

    Hello,
    You can try the following:
    Remove the calculate result as setting for the three KFs.
    In exception aggregation set property to average with ref char as leave start date.
    Check if it works.
    If the above dosent work, set reference char to emplyee ID and check.
    Either one of them has to work
    REgards,
    Shashank
    Edited by: Shashank Dighe on Apr 2, 2009 9:03 AM

Maybe you are looking for

  • Opening a socket from an applet

    I tried to open a socket from an applet to a server on a remote computer and I've got a refusal message. When I try it on a server in the local machine, it works. What could be the problem ? P.S. : when I open the socket from an application in the Ja

  • New non-leading ledger creation

    Hi, The new non-leading ledger to be created as per the client's requirement.  Can we create new non-leading ledger later on.  The old data to be posted to new non-leading ledger. Can someone throw light on this issue? What can be done please suggest

  • URGENT!!reports and lovs

    Oracle Portal Report I created an Lov named "tabb" to list the tables from a remote database. it works fine. i want to list the fields available in each table using the LOV. i used reports from SQL Query. i used the following query;owns is the dblink

  • Show description in KM navigation iview

    hi, all when i new a KM navigation iview, i can see the name, size,  last modify time. can i make some configuration to show description in the list? thx in advance.

  • Garageband Wonky after Mountain Lion Install

    I just upgraded to OS X Mountain Lion from Snow Leopard and now Garageband '09 (5.1) is acting weird.  It will let me start a new project but after working with the software instruments for a bit, Garageband will no longer let me add effects.  The ef