Grand Total SUM of COUNT

Hi all!
I am trying to grab a total of the COUNTS and SUM them together. I am trying to build a chart with graphics builder, but alas, that software has a 2000 character limit for its queries, so the inline view approach did not work. Here is my query:
SELECT
to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY') Base_Entry_Year,
count(*)
-- SUM(count(*)) does not work
FROM
per_all_assignments_f paaf,
per_all_people_f papf,
per_jobs pj,
per_job_definitions pjd
WHERE
papf.person_id = paaf.person_id
AND paaf.ass_attribute14 IS NOT NULL
AND to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY') IS NOT NULL
AND (papf.employee_number IS NOT NULL OR papf.person_type_id = 3)
AND paaf.job_id = pj.job_id
AND pj.job_definition_id = pjd.job_definition_id
AND pjd.segment1 NOT IN ('09140018', '09340006', '09140037', '09140051', '09140052', '09140054', '09140055')
GROUP BY
to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY')
ORDER BY
to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY')
Any ideas on how I can accomplish this? Thanks!
Steve

Hi,
I ran two different queries:
1.
select KeyCol, count(*), Sum(count(*)) over ()
  from Test t
group by t.KeyCol ;
Result:
        KEYCOL     COUNT     SUM(COUNT(*))OVER()
1     DHP     398     5505
2     FIH     1     5505
3     FIN     2971     5505
4     FLP     5     5505
5     HTBC     1     5505
6     Z99     22     5505
7          2107     55052.
select KeyCol, count(*), count(*) over ()
  from test t
group by KeyCol;
Result:
        KEYCOL     COUNT     COUNT(*)OVER()
1     DHP     398     7
2     FIH     1     7
3     FIN     2971     7
4     FLP     5     7
5     HTBC     1     7
6     Z99     22     7
7          2107     7This shows that both queries are not equivalent.
Thanks,
Dharmesh Patel

Similar Messages

  • Incorrect GRAND TOTAL (with COUNT DISTINCT)

    Hi,
    I'm getting wrong results in the GRAND TOTAL of a COUNT DISTINCT measure column.
    I have 5 distinct customers in Paris and 10 distinct customers in NYC, I want the grand total to retrieve the sum of both, that's 15.
    But OBIEE is calculating the distinct customers for all cities, so if there are customers in both Paris and NYC the result is wrong.
    This is the result I'm getting:
    City Number_Distinct_Customers
    Paris 5
    NYC 10
    GRAND TOTAL 12
    12 is the number of all the distinct customers.
    The correct GRANT TOTAL should be 5+10=15
    Thanks
    Regards

    So just as a weird question...from a business standpoint, what does the "15" mean?
    It's not a count of distinct customers, which is what this measure is supposed to be.
    If I were to come up with a business description for what's being described, it's "a count of distinct customers by city....summed up so that it is no longer a count of distinct customers". What and/or how exactly would anyone use such a number?
    Not trying to be a pain, just trying to figure out how this would be used.
    Thanks,
    Scott

  • Grand total is not working...please help

    Hi, here is my code
    SORT S_ENDT BY LIFNR.
      LOOP AT S_ENDT WHERE BUDAT IN P_BUDAT.
        WRITE:          1  S_ENDT-BKTXT,
                        11 S_ENDT-BUKRS,
                        16 S_ENDT-LIFNR,
                        24 S_ENDT-NAME1,
                        49 S_ENDT-BLART,
                        53 S_ENDT-BELNR,
                        64 S_ENDT-AUGBL,
                        75 S_ENDT-AUGDT,
                        86 S_ENDT-BUDAT,
                        97 S_ENDT-WRBTR,
                        113 S_ENDT-WAERS,
                        117 S_ENDT-XBLNR,
                        130 S_ENDT-ZUONR.
        AT END OF BKTXT.                         " Subtotal by Draft #
          ULINE.
          SUM.
          WRITE: 20 'Total of draft', 37 S_ENDT-BKTXT, 97 S_ENDT-WRBTR.
        ENDAT.
        AT LAST.                                 " Grand total
          SUM.
          SKIP.
          WRITE: 20 'Grand Total', 97 S_ENDT-WRBTR.
        ENDAT.
        SKIP.
      ENDLOOP.
    EXIT.
    ENDIF.
    I am not getting the right total..I am getting it for all LIFNR and not the value in P_LIFNR only (which is what I want).
    please help
    thanks
    Brian

    Hi,
    try this coding.
    SORT S_ENDT BY LIFNR.
    *data : gt(16) type p decimals 2.*
    LOOP AT S_ENDT WHERE BUDAT IN P_BUDAT.
    *gt = gt + S_ENDT-WRBTR.*
    WRITE: 1 S_ENDT-BKTXT,
    11 S_ENDT-BUKRS,
    16 S_ENDT-LIFNR,
    24 S_ENDT-NAME1,
    49 S_ENDT-BLART,
    53 S_ENDT-BELNR,
    64 S_ENDT-AUGBL,
    75 S_ENDT-AUGDT,
    86 S_ENDT-BUDAT,
    97 S_ENDT-WRBTR,
    113 S_ENDT-WAERS,
    117 S_ENDT-XBLNR,
    130 S_ENDT-ZUONR.
    AT END OF BKTXT. " Subtotal by Draft #
    ULINE.
    SUM.
    WRITE: 20 'Total of draft', 37 S_ENDT-BKTXT, 97 *gt*.
    ENDAT.
    AT LAST. " Grand total
    SUM.
    SKIP.
    WRITE: 20 'Grand Total', 97 S_ENDT-WRBTR.
    ENDAT.
    SKIP.
    ENDLOOP.
    EXIT.
    ENDIF.
    U are using where condition in a Loop ,while executing last record may or may not get executed becoz of restiction.Better declare a variable and SUM under such scenarios.
    Regards,
    Ballack.
    Reward Points if helpful.

  • Grand total feeding from Multiple Subjects Area

    Hi,
    I have to create a report that displays Grand total = sum of values from one subject area + sum of values from another subject area. How do i achieve this.
    Thanks

    Create a prompt based on the report(incl criteria) from SA1, include the measure column in the prompt, the value of the measure is based on the 'contrain' of each column in the prompt and assign to Presentation variable.
    Call Presentation variable in the report which is from SA2.
    ex: Report 1 from SA1 is like: $amount by year, by prodcut,by org
    Report 2 from SA2 is like: $OrderAmount by year, by prodcutType,by org
    Report1 by Prompt: Year->constrain, PRoduct->Constrain, Org-Constrain, $Amount as PS Var 'amt'
    Report 2 as reqular report, try to call @{amt} in the report for addition.

  • OBIEE11g Grand total not summing up correctly

    hi all,
    I have to display the grand total from the foll calculation : (total po numbers - total Recd on time PO numbers) / total PO numbers.
    To get the total PO numbers - in the Edit formula - COUNT(PO numbers) and aggregation rule is set to SUM - this gives total correctly. eg : count of Total PO numbers - 15
    To get the total Recd on time PO numbers-- In the edit formula fields - COUNT(Recd on time PO numbers) and aggregation rule is set to SUM . This also shows hte total correctly. Eg : Count of total Recd on time PO numbers 12
    Now I do the division (Recd on time PO numbers/ total PO numbers ) Again in the Edit formula field SUM( COUNT(PO numbers))/ SUM(COUNT(Recd on time PO numbers)) - This gives incorrect results. output is 12.
    12/15 should be .8 but it shows 12.
    I am not sure why its not doing the calculation correctly.
    Is there any way I can achieve this ?
    Thanks
    OBI_user

    * 1.00 => http://gerardnico.com/wiki/dat/obiee/int

  • Grand Total with Count Distinct

    Hi,
    I want to use grand total to count distinct my data,
    I had physical map ActivityId into my fact and set count distinct to its aggregation rules.
    then when i create my report the anwser is OK.(count distinct ActivityID). But in grandtotal is sum.
    The aggregation Rules in BI Awnser is set it Default.
    [Pic >> http://image.ohozaa.com/i/866/tablecountdisctinct.jpg ]
    i don't know why , i try to set many thing but it isn't work
    Thank ,Regard.
    And sorry about my English Language.

    couple of things required here..
    how did you build this measure in rpd?
    Is that physical mapped or logical mapped column(derived column)?
    Map it as physically and apply aggregation rule on top of it to: CountDistinct
    Now, pull the column in front-end it has to give you proper sub-total/total..
    Or, Try putting the formula in front-end in fx of the column and try..

  • 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

  • Grand Total on Count Distinct - Crosstab

    Hello
    I use Discoverer 9.0.2.39.01.
    On a crosstab layout: the data point is a count distinct item ,
    I use Grand total at bottom and also Grand total at right.
    Both totals are displayed correct but the cell combining between them is blank.
    The join between the two tables is one to one and I use NVL on the count distinct item. how can I overcome the problem and cuase th blank cell to display the result of both totals?

    I'd just reiterate a couple of things to try.
    1. reverse the join - I realize you mentioned it seems to work for simple total, but this has to be one of the most popular errors
    2. check for NULLs in the data (ie: to_number(NVL(item, '0')), etc.
    If still not working, then logically, what would be causing a count of distinct items not to display (ie: NULL would explain it as I would think the COUNT would screw up with not knowing how to handle a NULL).
    By why count(item) would work and count_distinct(item) wouldn't is an interesting problem.
    Russ

  • Grand Total Issue - Weighted Sum

    Here's the Issue
    3 Columns
    Hours Worked, Pay Amount, and Pay Rate
    20 10 $.50
    Pay Rate is a calculated column from "Hours Worked" and "Pay Amount"
    I'm trying to add the grand total to my work sheet for "Pay Rate"
    Discoverer simply adds all of the "Pay Rate" values.
    I would like the Pay Rate grand total to be "Pay Amount Grand Total" / "Hours Worked Grand Total"
    Is this even possible?

    If you're using 10g, take a look at your aggregation options (tools/aggregation). Since Pay Rate is a calculated column, there should be an option that forces it to do a calculation on the totals (rather than a total of the calculation). If you're on an older version, you may need to look into the aggregation-related registry settings/preferences. Also make sure you're doing a sum (not a cell sum).
    That behavior seems to change from version to version but if you search on MetaLink you should find some version-specific help.

  • Displaying Distinct Count as Grand Total

    Hi -
    I have a requirement where i have to show the distinct count of Transaction Numbers at the bottom of the report as Grand Total. I created a dummy column with Fx as MAX(RCOUNT(1)) and used it in Narrative view and it is showing me the total rowcount whereas i want the distinct rowcount based on Transaction number column in my report.
    Any help is appreciated!
    Thanks
    R

    Instead of using a RCOUNT you can use the COUNT(DISTINCT <Transaction Number Column>) in your column formula
    This is an inbuilt function.
    Mark if it helps..

  • Question regarding adding sums in 3 tables for a grand total

    Can someone please help me with this.  I have the coding in the tables to add table 6, 7, and 8 but each time I add or delete a row the coding gets messed up.  It is adding in some places but not on each row.  I don't know the coding to use to avoid this problem everytime you add or delete a row.  I just need all tables to add up for a grand total.

    If this is the resultyou are looking for the attached will help.
    Steve
    Please post LiveCycle Designer ES questions in that forum in the future.

  • MDX - TOP COUNT AND GRAND TOTALS

    I need to get ONLY the TOP 25 suppliers based on the NET Revenue, but I need also the GRAND TOTAL for all the suppliers.
    Is that possible to accomplish using an MDX query?

    thanks, but it is not what i want.
    here an example (with top 4 instead of 25)
    suppliers              Net Amt
    1054                    $500          visible
    1053                    $100        visible
    1058                    $50           visible
    1044                    $40           visible
    1022                    $20         NOT visible
    1045                    $20            NOT visible
    TOT                    $730  ------> this is the total I want
    I hope it is more clear
    mcrisf

  • % of calculation in GRAND TOTAL in PIVOT TABLE

    Hi Gurus,
    I have a requirement to calculate the percentage based on the grand total in pivot table,but in row wise i am getting the percentage while in grand total level i am not getting correct values.I have tried with all the options like:average,Sum,Default,Max,Min,count etc and also with the percent of row,column,parent column etc.
    Please give me a solution for this ASAP.
    view of my table is
    Previous Value||Present Value||change between Pres & Prev||% of change(((pres - prev)/pres)*100)
    10||20||10||50%
    00||01||01||100%
    10||05||-05||-50%
    here i should get values in grand total like
    20||26||06||23%
    but i am getting values when giving sum for %of calc in measures values
    20||26||06||100%
    if i give avg for %of calc in measures values then i am geting
    20||26||06||33%
    how to solve this prob.Can any one give sol plzzzzzzzz
    Thanks,
    Naveen

    Hi,
    Refer : http://www.skurabigroup.com/blog/?p=579
    Regards,
    Srikanth

  • Using Subquery in Select with Rollup (or some way to get grand total)

    I am trying to do the following (simplified the query):
    SELECT s.SYSTEM,
    (SELECT COUNT(cp1.cid) FROM cfrs cp1, systems sp1, subsystems ssp1 where cp1.priority = 'P1' AND cp1.subsystem = ssp1.subsystem AND sp1.system = ssp1.system AND sp1.system = s.system) AS P1
    FROM cfrs c, systems s, subsystems ss
    WHERE c.subsystem = ss.subsystem
    AND s.system = ss.system
    GROUP BY ROLLUP(s.SYSTEM)
    But the result of the Rollup on the P1 column is always 0 (it is not summing it up)
    How can I accomplish a Rollup (or get a grand total) of the subquery result?
    Thanks,

    How about this then:
    SQL &gt; WITH SYSTEMS AS
      2  (
      3     SELECT 'A' AS SYSTEM FROM DUAL UNION ALL
      4     SELECT 'B' AS SYSTEM FROM DUAL UNION ALL
      5     SELECT 'C' AS SYSTEM FROM DUAL
      6  ),
      7  SUBSYSTEMS AS
      8  (
      9     SELECT 'A' AS SYSTEM, '1' AS SUBSYSTEM FROM DUAL UNION ALL
    10     SELECT 'A' AS SYSTEM, '2' AS SUBSYSTEM FROM DUAL UNION ALL
    11     SELECT 'A' AS SYSTEM, '3' AS SUBSYSTEM FROM DUAL UNION ALL
    12     SELECT 'B' AS SYSTEM, '4' AS SUBSYSTEM FROM DUAL UNION ALL
    13     SELECT 'B' AS SYSTEM, '5' AS SUBSYSTEM FROM DUAL UNION ALL
    14     SELECT 'B' AS SYSTEM, '6' AS SUBSYSTEM FROM DUAL UNION ALL
    15     SELECT 'C' AS SYSTEM, '7' AS SUBSYSTEM FROM DUAL UNION ALL
    16     SELECT 'C' AS SYSTEM, '8' AS SUBSYSTEM FROM DUAL UNION ALL
    17     SELECT 'C' AS SYSTEM, '9' AS SUBSYSTEM FROM DUAL
    18  ),
    19  CFRS AS
    20  (
    21     SELECT 10 AS CID, '1' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    22     SELECT 11 AS CID, '1' AS SUBSYSTEM, 'LOW' AS PRIORITY FROM DUAL UNION ALL
    23     SELECT 12 AS CID, '1' AS SUBSYSTEM, 'MED' AS PRIORITY FROM DUAL UNION ALL
    24     SELECT 13 AS CID, '2' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    25     SELECT 14 AS CID, '2' AS SUBSYSTEM, 'MED' AS PRIORITY FROM DUAL UNION ALL
    26     SELECT 15 AS CID, '2' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    27     SELECT 16 AS CID, '3' AS SUBSYSTEM, 'LOW' AS PRIORITY FROM DUAL UNION ALL
    28     SELECT 17 AS CID, '3' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    29     SELECT 18 AS CID, '4' AS SUBSYSTEM, 'MED' AS PRIORITY FROM DUAL UNION ALL
    30     SELECT 19 AS CID, '5' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    31     SELECT 20 AS CID, '5' AS SUBSYSTEM, 'LOW' AS PRIORITY FROM DUAL UNION ALL
    32     SELECT 21 AS CID, '6' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    33     SELECT 31 AS CID, '7' AS SUBSYSTEM, 'LOW' AS PRIORITY FROM DUAL UNION ALL
    34     SELECT 41 AS CID, '8' AS SUBSYSTEM, 'HIGH' AS PRIORITY FROM DUAL UNION ALL
    35     SELECT 51 AS CID, '9' AS SUBSYSTEM, 'MED' AS PRIORITY FROM DUAL UNION ALL
    36     SELECT 61 AS CID, '9' AS SUBSYSTEM, 'MED' AS PRIORITY FROM DUAL
    37  )
    38  SELECT DECODE(SYSTEM,'ALL_SYSTEMS','Grand Total',SYSTEM) AS SYSTEM
    39  ,  MAX(DECODE(PRIORITY,'LOW',CNT,0))       AS LOW
    40  ,  MAX(DECODE(PRIORITY,'MED',CNT,0))       AS MED
    41  ,  MAX(DECODE(PRIORITY,'HIGH',CNT,0))      AS HIGH
    42  ,  MAX(DECODE(PRIORITY,'ALL_PRIOR',CNT,0)) AS SYSTEM_TOTAL
    43  FROM
    44  (
    45     SELECT DECODE(GROUPING(SYSTEMS.SYSTEM),1,'ALL_SYSTEMS',SYSTEMS.SYSTEM) AS SYSTEM
    46     , DECODE(GROUPING(CFRS.PRIORITY),1,'ALL_PRIOR',CFRS.PRIORITY) AS PRIORITY
    47     , COUNT(*) AS CNT
    48     FROM SYSTEMS
    49     JOIN SUBSYSTEMS ON SYSTEMS.SYSTEM = SUBSYSTEMS.SYSTEM
    50     JOIN CFRS ON SUBSYSTEMS.SUBSYSTEM = CFRS.SUBSYSTEM
    51     GROUP BY CUBE(SYSTEMS.SYSTEM,CFRS.PRIORITY)
    52     ORDER BY SYSTEMS.SYSTEM, CFRS.PRIORITY
    53  )
    54  GROUP BY DECODE(SYSTEM,'ALL_SYSTEMS','Grand Total',SYSTEM)
    55  ORDER BY DECODE(SYSTEM,'ALL_SYSTEMS','Grand Total',SYSTEM)
    56  /
    SYSTEM             LOW        MED       HIGH SYSTEM_TOTAL
    A                    2          2          4            8
    B                    1          1          2            4
    C                    1          2          1            4
    Grand Total          4          5          7           16Oh, BTW, use "code" wrapped in "{}" on either side to post nicely formatted code.

  • Grand Total in Pivot Table

    Hi, I have a pivot table with several measures and grand totals. The problem is that there is one measure where the totals show up incorrectly. By incorrectly I mean that this shouldn't be sum of rows, but a different calculation and I haven't found a way to define separate calculation for this total.
    Is there a way to hide totals for this one measure? Or is it still somehow possible to use some different value/calculation in there?

    In the Pivot Table I'm currently using sum, because I'm combining different queries with union. In the actual query these values are calculated by row using Count Distinct. Now in the total it just sums up individual Count Distinct values but the correct value should be Count Distinct for total data set.

Maybe you are looking for

  • How to polulate data from lookup using request dataset in OIM 11g

    Hi, Using Request dataset in OIM 11g, I need to display one dropdown with the roles those need to come from Lookup. For Ex; I have 2 resources,i.e Resource A and Resource B. Resource A has 5 roles and Resource B has 3 Roles. While creating a request,

  • Open Item management-4.6c version

    Hi Gurus, Unfortunately I created some GL accounts as a Balance sheet account and I activated  open item management. Now the requirement is need to deactivate the open item management and fix the P&L. Account. Pls guide me step by step. Regards, Bhar

  • Copy contents of one table to another

    Hi, Can anyone will give me the code copying the contents of one table to another... Need an urgetn help.. Thanks

  • Mass change of the Original System

    Hello Experts!!! We need to do a massive change of the original system to avoid repair tasks. I know that thru SE03 or SM30->TADIR is possible, but we need to do it to all objects in the system.... I think It might exist a standar tool for that... wh

  • Convert HTML codes to RTF

    Hi, In a Java Servlet, I need to convert HTML codes into an RTF/word document. Any help for some related Java API ? Regards, Priya Ranjan Sahay Message was edited by: Priya Ranjan Sahay