Sum distinct

I have 3 elements here
Category      Account      Amount
A          1          100
A          1          100
A          2          200
B          2          300
B          2          300
B          2          300
i need the sum of category A as 300 ( for distinct account codes) and sum of category B as 300
Please help
Ramanathan

<?xml version="1.0"?>
<!-- Generated by Oracle Reports version 6.0.8.25.0 -->
<MODULE1>
<LIST_G_EMPNO>
<G_EMPNO>
<EMPNO>A</EMPNO>
<ENAME>1</ENAME>
<JOB>100</JOB>
</G_EMPNO>
<G_EMPNO>
<EMPNO>A</EMPNO>
<ENAME>1</ENAME>
<JOB>100</JOB>
</G_EMPNO>
<G_EMPNO>
<EMPNO>A</EMPNO>
<ENAME>2</ENAME>
<JOB>200</JOB>
</G_EMPNO>
<G_EMPNO>
<EMPNO>B</EMPNO>
<ENAME>2</ENAME>
<JOB>300</JOB>
</G_EMPNO>
<G_EMPNO>
<EMPNO>B</EMPNO>
<ENAME>2</ENAME>
<JOB>300</JOB>
</G_EMPNO>
<G_EMPNO>
<EMPNO>B</EMPNO>
<ENAME>2</ENAME>
<JOB>300</JOB>
</G_EMPNO>
</LIST_G_EMPNO>
</MODULE1>
<?for-each-group:G_EMPNO;EMPNO?>
<?xdoxslt:set_variable($_XDOCTX, ’R’,0)?>
<?for-each-group:current-group();ENAME?>
<?xdoxslt:set_variable($_XDOCTX, ’R’,xdoxslt:get_variable($_XDOCTX, ’R’)+JOB)?>
<?end for-each-group?>
<?EMPNO?> <?xdoxslt:get_variable($_XDOCTX, ’R’)?>
<?end for-each-group?>

Similar Messages

  • How to get sum distinct in the cube. Is it possible.

    Here is the scenario.
    One report has many countries on it but only one amount.
    For a particular day we have the following data in the fact.
    TRANSACTION_DAY_NO
    Country
    Total Amount
    19900101
    US
    34
    19900101
    IND
    35
    19900101
    IND
    36
    19900101
    AUS
    37
    19900101
    UNKNOWN
    38
    19900101
    UNKNOWN
    39
    19900101
    UNKNOWN
    40
    19900101
    UNKNOWN
    41
    19900101
    UNKNOWN
    42
    19900101
    UNKNOWN
    43
    19900101
    US
    43
    19900101
    IND
    42
    There are 2 dimensions on the cube.
    Date, Country.
    I am not sure how to build a cube on this data.
    with t as (
    select 19900101 transaction_Day_no,     'US' country_no,     34 total_amount from dual union all
    select 19900101,    'IND',         35  from dual union all
    select 19900101,    'IND',         36  from dual union all
    select 19900101,    'AUS',         37  from dual union all
    select 19900101,    'UNKNOWN',    38  from dual union all
    select 19900101,    'UNKNOWN',    39  from dual union all
    select 19900101,    'UNKNOWN',    40  from dual union all
    select 19900101,    'UNKNOWN',    41  from dual union all
    select 19900101,    'UNKNOWN',    42  from dual union all
    select 19900101,    'UNKNOWN',    43  from dual union all
    select 19900101,    'US',    43  from dual union all
    select 19900101,    'IND',    42  from dual
    select transaction_day_no, country_no, sum(distinct total_amount) from t
    group by cube(transaction_Day_no, country_no);
    I am using AWM. I have tried to build by selecting the following aggregate for the cube
    max for the country_no and
    sum for the tranaction_Day_no
    But i am getting incorrect results.
    If i select sum for both country_no and transaction_no then also i get incorrect results.
    Please help me solve this issue.
    thanks

    Thanks for all your reply's.
    The problem is that i have duplicates because
    One report can have many customers.
    One customer can have many countries.
    One customer can have many reports.
    If i include the report number in the above data and do a sum on both day and report_number and max for everything else then everything is find and i am getting correct results.
    But if i take out the report dimension then i am stuffed.
    Also the problem is that i can't have one big dimension for the report as the number of reports are in access of 300M
    We have tried to solve this issue by having the fullowing.
    Dummy Cube.
    This has all the combination of all the dimension in the fact table with the report dimension as only one row(-1)
    Report Dimension for each Quarter(34M rows each)
    Quarter Cube is build.
    Then add the values from all the Quarter Cube with the Dummy Cube.
    Tried for 2 Quarter and its working fine results are correct as well.
    Only problem is that its taking a long time to build the cube because of the report dimension.
    I am trying to find a way to remove the report dimension but still use it. As we only use report dimension at level 'ALL'
    But if we do aggregation at 'ALL' level the answers are wrong again.
    Thanks for looking into this and taking time to reply.
    Regards
    Alvinder

  • Select sum(distinct column ) from ....

    Hello All,
    I have a table the contains ID and size.
    An ID identifies a unique object, but it can be repeated. The following is valid:
    ID Size
    1 3
    4 5
    5 3
    1 3
    What I am trynig to do is get the sum of all sizes in the table. I tried this query:
    select sum(distinct size) from table;
    But it does give the right result since different objects could have the same size. I tried
    select sum(size) group by ID;
    But it prints to me huge number of IDs and sums the sizes of an ID together. What I want thuogh is to look at the unique rows (without duplicates) and then sum their sizes together and get the result.
    Any help would be greatly appreciated.
    Thank you
    P.S.: Sorry, I am an absolute Oracle/SQl newbie.
    Thanks for your help in advance

    An ID identifies a unique object, but it can be repeated.Fnord.
    I think your data model could withstand some refactoring but what you need to do is:
    SELECT sum(size) FROM
      (  SELECT distinct id, size FROM your_table)
    /This of course assumes that your duplication is complete and you don't have duplicate IDs with different sizes.
    You still ought to check out the concept of UNIQUE constraints though. A database ain't a database without relational integrity.
    Cheers, APC

  • Sum Distinct for a measure object

    Hi,
    Can anybody let me know how to go ahead and get a sum distinct for a particular measure object in a Universe?

    If your database supports the syntax, you can simply use SUM(DISTINCT table.measure_column) and it should apply the distinct function. Note, however, that this can result in under-reporting certain values. For example, assume you have two sales orders with the same amount: $100. As long as you include the order number (or primary key order_id or otherwise) you will get a total of $200. But if you remove order number, the sum(distinct) will see two equal values (both $100) and your total will only be $100 instead of the correct answer $200.
    What is the real problem you are trying to solve?

  • Sum distinct by multiple key

    How do I sum the first observation of a field from many observations with the same key. (sum distinct by multiple key)?

    And if it fits your requirements:
    select column, sum(distinct column)
    from table
    group by column;
    -cf
    (btw, how do you make your SQL appear in Courier font?)
    Message was edited by:
    [email protected]

  • 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

  • Kind of sum distinct

    Hi to everybody...i have to solve a big problem, and i can't find a way to get it..
    i have a table like this
    Italy 1000
    Spain 2000
    Germany 1500
    and for some reason, i have to make a join, so the result is a duplicate rows...
    Italy 1000 AA 50
    Italy 1000 BB 50
    Italy 1000 AA2 100
    Italy 1000 CC 1500
    Spain 2000 DD 100
    Spain 2000 AA 30
    Spain 2000 FF 50
    Germany 1500 AA 100
    Germany 1500 NN 200
    in this table that i get, i have , WITH A SINGLE SELECT STATEMENT (beacuse i have to use business object)
    Count the number of countries -> count( distinct country)
    Sum the import that i had in the first table...so i have to get 1000+2000+1500
    (it's like a sum of import for distinct countries).
    How i can do this using a single select? I know the way to do it using 2 select, one inside the other, but i can't use it in business object.
    Thank's in advance!
    Edited by: user13012184 on 5-mag-2010 3.07

    Hi,
    user13012184 wrote:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    create table PROVA1
    COUNTRY VARCHAR2(50),
    IMPORT NUMBER
    insert into PROVA1 (COUNTRY, IMPORT)
    values ('Italy', 1000);
    insert into PROVA1 (COUNTRY, IMPORT)
    values ('Spain', 2000);
    insert into PROVA1 (COUNTRY, IMPORT)
    values ('Germany', 1000);
    commit;
    select sum(import) from prova1 t
    [4000]
    create table PROVA2
    COUNTRY VARCHAR2(50),
    CITY VARCHAR2(50)
    insert into PROVA2 (COUNTRY, CITY)
    values ('Italy', 'Trieste');
    insert into PROVA2 (COUNTRY, CITY)
    values ('Italy', 'Venezia');
    insert into PROVA2 (COUNTRY, CITY)
    values ('Spain', 'Barcellona');
    insert into PROVA2 (COUNTRY, CITY)
    values ('Germany', 'Berlino');
    insert into PROVA2 (COUNTRY, CITY)
    values ('Germany', 'Colonia');
    commit;
    select sum(import) from prova1 t1 ,prova2 t2
    where t1.country=t2.country
    [6000]That's an excellent reply to Centinul's items 1. and 2.:
    Centinul wrote:
    It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.Keep up the good work! Post items 3., 4. and 5. as well.
    >
    but i would like to have [4000], the sum of a import for every distinct country...Is that the answer to "3. Expected output"? If so, you already posted the answer yourself:
    SELECT  SUM (import) AS sum_of_import
    FROM     prova1          t
    ;Prova2 plays no role in this problem. That's fine: you won't use every table in every query.

  • Sum Distinct Count

    Is there a way to sum a distinct count?
    I have a distinct count placed on GF2 and need the Sum of the Distinct count of GF1.
    Is this possible?
    Thanks for any help and suggestions,
    Jen

    Hi Jen,
    Try this:
    1) Create a formula on the Group Footer 2:
    WhilePringtingRecords;
    Numbervar dc;
    dc := dc + distinctcount({database field}, {group});
    2) Create another formula to display the sum and place this on the GF1:
    WhilePringtingRecords;
    Numbervar dc;
    3) Create a reset formula and place it on the GH1:
    WhilePringtingRecords;
    Numbervar dc := 0;
    -Abhilash

  • SUM distinct in SSAS Cube measure

    Hi All,
    I am new to SSAS. I am building a cube. I have many to many relationship.
    The fact table is structured as below
    FactMain:
    DataSetId   TotalCost
    Data
    101   100.00
    102   200.00
    FactBridge:
    DataSetId    CodeKey   CodePosition
    Data:
    101     1   1
    101     1   2
    102     5   1
    DimCode:
    CodeKey   CodeDescription
    1        Code1
    2        Code2
    5        Code 5
    If I am browsing the cube for Code1
    I am getting TotalCost doubled. (200.00) Actually I need to get 100 only as it is same DataSetId
    How can I get SUM(TotalCost) for distinct DataSetIds?

    Hi Rajkm,
    According to your description, you want to sum the value for distinct dataset. Right?
    In this scenario, since you build the relation between main and bridge table, it will have two records for code1. So when you calculate the total cost on code dimension, it will definitely aggregate the value for each CodeKey. So your requirement
    can't be achieved. If you want to keep only one value for each code, you should not have that bridge table in you dsv when building your cube.
    If you have any question, please feel free to ask.
    Simon Hou
    TechNet Community Support

  • Sum distinct values grouped in ssrs expression

    Hi ALl
    Need help in writting an expression
    I have this kind of data 
    C1 L1
    10
    C1 L2  
    10
    C1 L3
    10
    C2 L1
    3
    C2L2 
    3
    C3  L1 6
    C3 L2 
    6
    Need to write an expression in SSRS calculated fieldwhich will sum  only C1L1 + C2 L1 +C3L1?
    Is this possible ? Can somebody please help

    Hi,
    After testing the issue in my local environment, we can refer to the expression below to achieve your requirement (supposing that the L1,L2,L3 in col2 field, 10,3,6 in value field, the dataset named DataSet1):
    =SUM(IIF(Fields!col2.Value="L1",Fields!value.Value,0),"DataSet1")
    If there are any other questions, please feel free to ask.
    Thanks,
    Kathrine Xiong
    Katherine Xiong
    TechNet Community Support

  • Problem in using sum with distinct in case

    Hi all,
    I want to use a sum function with distinct and also with case.
    below is the format i am using.
    Sum( distinct case when a.value='TOOL' then e.value else 0 end)
    This is working but i don't get distinct records.
    SO i tried using in this way
    Sum( case when a.value='TOOL' then distinct e.value else 0 end)
    But I am getting missing expression error.
    Please help me to resolve this issue
    Thanks
    Priya

    STEP -2
    SQL>
    SQL> commit;
    Commit complete.
    SQL> ed
    Wrote file afiedt.buf
      1  Select Sum(Value)
      2  From (
      3          Select Distinct Case when value='TOOL'
      4                               then value
      5                          else
      6                              0
      7                          end Value
      8          From Blah
      9*      )
    SQL> /
                                0
    ERROR at line 6:
    ORA-00932: inconsistent datatypes: expected CHAR got NUMBERRegards.
    Satyaki De.

  • 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

  • Sum ?

    Dear friends,
    Is there any way to display this number in readable format (without scientific notation) and without setting column format.
    SQL> select sum(distinct s) total from hgtbs2m where s <> trunc(s);
      TOTAL
    7.3E+10
    "I need output as given below,  without setting column format"
    TOTAL
    72645584085.37Is it possible?

    Another option in SQL*Plus is to change the default format for displaying numbers
    SET NUMFORMAT 99999999999.99http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch3.htm#1005686
    Corrected my posting NUMWIDTH was the wrong parameter, should be NUMFORMAT
    Message was edited by:
    Jens Petersen

  • Using Sum Function in Oracle(on 24 th)

    Hi all i wrote the following query.
    SELECT RESPONSER_ID,SUM(SUM(DISTINCT WORK_SPACE)) AS SCORE,COUNT(DISTINCT QUESTION_ID) AS QCOUNT FROM TQDB_LEARNER_RESPONSE WHERE RESPONSER_ID=328
    GROUP BY RESPONSER_ID
    I am getting the following error.
    ORA-00937: not a single-group group function
    Any body Pls help me.

    why use sum(sum()
    SUM(SUM(DISTINCT WORK_SPACE)) AS SCORE,
    SELECT
         RESPONSER_ID,
         SUM(DISTINCT WORK_SPACE) AS SCORE,
         COUNT(DISTINCT QUESTION_ID) AS QCOUNT
    FROM
         TQDB_LEARNER_RESPONSE
    WHERE
         RESPONSER_ID=328
    GROUP BY
         RESPONSER_ID Regards
    Singh

  • Urgent!! Sum function for subtotals.,Exporting BA does not list Workbooks

    Hi,
    I m facing this issue when calculating subtotals in the report. When i use the sum function, the subtotals are not getting displayed. I tried usin the Cell Sum Distinct function and it sums up only if the amounts are different. For example when i have two amounts of 5.00 each, it sums as 5.00 only in the subtotal. Can anyone help me resolve this?
    Also, i m facing one more issue. When i export the BA, the user wants the list of workbooks under that that would be exported. (The list is shown when exporting the EUL as such), but the list is just blank in BA export. Is this a set up issue?
    Thanks in advance.

    Hi,
    Not all calculations can be summed correctly by Discoverer. What is the calculation that you are trying to sum?
    The workbooks are not tied to a BA as the folders used in a workbook may be in many different BAs. Therefore the workbooks are not exported with a business area. The workbooks must be exported separately.
    Rod West

Maybe you are looking for