Sum a distinct record

Post Author: hamish_sco
CA Forum: Formula
Hi there, I wondered if anyone knows if it is possible to do the following;I have data columns for 'invoice number', 'amount' and 'amount paid'.There is some duplication in the data - an invoice can be paid in several installments, but this puts in a new row containing the invoice number and amount.  When the data is Sum then it is incorrect.I can do a distinct count to find the actual number of invoices, but I would like also to Sum the amount of all invoices, but this needs to ignore any duplicate entries. Obviously this should ideally be done database side, but the procedures I have do not allow this, so I wondered if this could be done Crystal side? CheersHamish

duplicate data is generally caused by joining multiple tables with multiple similar records, if you can not surpress this in the stored procedure a work around in the report would be
create a group for  'invoice number', 
place the fields  'invoice number', 'amount' and 'amount paid'.in the group header( the header will return the first value it hits for the grouping)
in order to get correct values on duplicate data you would need to use manual running totals(dont use the wizard)
create 3 formulas
reset formula (gets placed in the group header)
whileprintingrecords;
numbervar x := 0;
calc formula (gets placed next to value that needs to be calculated)
whileprintingrecords;
numbervar x :=  x +{field or formula};
display formuls (gets placed in footer)
whileprintingrecords;
numbervar x;
x

Similar Messages

  • 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.

  • Distinct records

    hi all,
    i am calculating sum for one column but i want sum for the distinct records from the table
    SELECT D_NUMBER,D_TYPE,SUM(D_AMT)
    FROM D_TABLE
    WHERE D_CODE =:PARAMETER
    GROUP BY D_NUMBER,D_TYPEin the above case D_NUMBER,D_TYPE may repeat i want the amount for distinct records. how can i for a query to get (tried with distinct but not getting the correct sum..
    Thanks..

    Hi,
    so you searching for something between d_number,d_type and d_amt and the sum of d_amt based on the first two. Then you need a differentiator, how do you do make the first 2 distinct based on some other column, so these 3 will be distinct, otherwise it will not be possible, except if you say the first 3 rows belong together, and that is what I want to be summed.
    Herald ten Dam
    htendam.wordpress.com

  • Actuate to BIP Conversion Need Help with Sum and Distinct

    Hi,
    I am in the process of converting an Actuate report to BI Publisher .rtf format. Within the actuate report I have encountered the following code in one of the fields:
    Sum([ssCalc])Distinct([ssProfessional_Id])
    From what I understand this Actuate code is grouping by distinct ssProfessional_Id then taking the sum of the ssCalc field.
    In my .rtf template I have the following:
    <?for-each-group:ssSRA;./ssCIN?>
    <?ssCalc?>
    <?end for-each-group?>
    I need to convert the Actuate code into the place where I currently have <?ssCalc?> in my template but I have no idea how I can translate translate this. Does anyone have any suggestions?????
    Thanks,
    Fred

    Fred
    Can you post the XML, easier to help then
    Tim

  • How can I get the number of distinct records that each field of a DB table has?

    Hi everyone,
    I would like to know how to get he number of distinct records that each field of a DB table has. When tracing a SQL statement either in ST12 or ST05, in the plan execution, if the sentence made useage of an index, then I can click in the index name and see this kind of information (no. of distinct values for each field of that index).
    Can I do something like this but with the whole fields of a table?
    What I have found until now is in Tx ST10; I search for whatever kind of table statistics and then use the function of "Analyze table" (which takes me to Tx DB05). In here, I can enter a table and up to 5 fields in order to get the information that I want.
    Is there any other way to do this?
    Regards,
    David Reza

    Hi David,
    You can export the same to excel and sort as per requirement.
    Sorry is that what you are looking for ?
    Regards,
    Deepanshu Sharma

  • Select distinct records in Mapping with no Key field (all fields can vary)

    Hi Experts,
    Let me take an example (not the actual requirement but same scenario) to explain the problem where I need your help to get best possible way to resolve. This has to be achieved in mapping, don't have other options as its part of complex end 2 end scenario.
    I have following input XML:
    <Employee>
       <Details>
          <Id>123</Id>
          <Name>ABC</Name>
         <Role>Manager</Role>
          <Area>Bangalore</Area>
        </Details>
        <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Pune</Area>
         </Details>
          <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Advisor</Role>
             <Area>Bangalore</Area>
         </Details>
          <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Bangalore</Area>
           <Details>
           <Id>143</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Bangalore</Area>
         </Details>
    </Employee>
    The output XML is:
    <Employee>
       <MainRec>
           <Id>123</Id>
            <Name>ABC</Name>
             <table name = 'Roles'>
                   <record>
                          <Id>123</Id>
                           <Role>Manager</Role>
                            <Area>Bangalore</Area>
                      </record>
                      <record>
                          <Id>123</Id>
                           <Role>Manager</Role>
                            <Area>Pune</Area>
                      </record>
                      <record>
                          <Id>123</Id>
                           <Role>Advisor</Role>
                            <Area>Bangalore</Area>
                      </record>
                  </table>
          </MainRec>
          <MainRec>
            <Id>123</Id>
            <Name>ABC</Name>
             <table name = 'Roles'>
                   <record>
                          <Id>143</Id>
                           <Role>Manager</Role>
                            <Area>Bangalore</Area>
                      </record>
                </table>
            </MainRec>
    </Employee>
    As you can see from the example above, here I want to populate only distinct records under table, but there is no key fiield to ditunguish. Any of the 3 fields (Id, Role,Area) can vary and between 2 records if all of these fields are same then its duplicate else select it. So in above XML just discard the 4th record from the source XML and populate all others. Each record has to be checked against all other records all 3 values (ID, Role, Area). Only when none of the records have exactly the same values, populate it.
    Also records with different ID come under different table node. Hope my requirement is clear, if not please let me know, i will try to explain better.
    I thought of creating a UDF to achieve this but not able to decide how to match it to the output message here.
    Best Regards,
    Pratik

    Hi,
    For the main record, I think you only need to check for each unique ID, e.g
    Id --> removeContext --> sort:ascending --> splitByValue:valueChanged --> collapseContext --> MainRec
    For the record, however, you need to create a UDF that will filter out the duplicate values. For this, the UDF sample mentioned here contained multipleResult lists
    Id --> removeContext --> concat: : --> concat: : --> UDF --> splitByValue:ValueChanged --> record
    role --> removeContext --> /          /                \ --> Id
    area --> removContext -------------> /                  \ --> role
                                                             \ --> area
    Context type UDF
    Arguments: input
    Result: IdResult
    Result: roleResult
    Result: areaResult
    Vector temp = new Vector();
    for(int a=0;a<input.length;a++){
       if(!temp.contains(input[a])
             temp.add(input[a]);
    for(int a=0;a<temp.size();a++){
       String tmp = (String) temp.get(a);
       /*split according to field */
       IdResult.addValue(tmp.substring(0,tmp.indexOf(":")));
       roleResult.addValue(tmp.substring(tmp.indexOf(":")+1,tmp.lastIndexOf(":")));
       areaResult.addValue(tmp.substring(tmp.lastIndexOf(":")+1,tmp.length()));
    note: Id and record will both be using the IdResult list.
    Hope this helps,
    Mark

  • How to distinct records?

    hi,
    i need to distinct records in my query but i don't know how to do that.
    i use SQLX functions. this is my query:
    select xmlelement ("narqdi",
    xmlelement ("order",
    (select xmlagg (
    xmlconcat (
    xmlelement ("nom_order", nor.nom_order),
    xmlelement ("nch", nor.chnom1),
    xmlelement ("partida",
    (select xmlagg (
    xmlconcat (
    xmlelement ("npartida", nor2.npartida),
    xmlelement ("ppnom",
    (select xmlagg (xmlelement ("pnom", nor3.pnom))
    from narqd_order nor3
    where nor3.nom_order = nor2.nom_order
    and nor3.npartida = nor2.npartida
    from narqd_order nor2
    where nor2.nom_order = nor.nom_order
    from narqd_order nor
    where nor.NOM_ORDER = '5970'
    from dual
    i have 18 records in table for record nom_order = '5970' and i receive 18 tags <partida> and 18 tags for each ppnom :(
    please help me.
    i tried to put distinct in every select but this is no reason.
    i tried to put agregate function in each select statement but in select for <pnom> it does not work...
    best regards
    Message was edited by:
    Fitibaldi
    Message was edited by:
    Fitibaldi

    Arti,
    Here's another solution (that will still use locking, and can help avoid the "lost update" problem):
    http://stegemanoracle.blogspot.com/2006/03/using-updatable-views-with-adf.html
    John

  • Value Set whose Data come from customize table with distinct record

    Dear All,
    I am new in Oracle EBS, currently i am creating value set whose data come from customize table which have 40 duplicate record in which distinct column return 27 record .
    Table XX_ROUND_SET
    Columns (Transactions_id,set_record)
    Total Record (40)
    Distinct Record (Set_Record --> 27)
    I just want to show only 27 record in it.
    Thanks
    Rehan

    Hi Rehan,
    PL.IGNORE MY EARLIER UPDATE AND TREAT THIS UPDATE AS YOUR SOLUTION.
    Method 1
    Create the VIEW based on DISTINCT values; use the VIEW for creates the VALUESET.
    Method 2
    Paste the QUERY in TABLE field with alias name, and give the column name (with alias name).
    (in your case )
    TABLE NAME : ( select distinct transactions_id, set_record from XX_ROUND_SET ) Y
    VALUE : Y.transactions_id
    HTH
    Sanjay

  • "Select Distinct Records" Option Not Available

    Hello Experts.
    I am working on a new report in CR XI, and noticed that I had many duplicate records.  I went to the File; Report Options; and expected to click on "Select Distinct Records", but that choice was grayed-out.  What would have caused me to lose this option, and how do I fix it?
    Thanks in advance for your help.

    Not sure if this covers it or not, but....
    The Select Distinct Records command is only available for ODBC, OLE DB, and SQL native drivers; it is not available for Stored Procedures. Note also that your server may automatically sort returned values if no sort is specified in Crystal Reports.

  • Distinct records with conditional select formula

    Post Author: nelsonchris
    CA Forum: Data Connectivity and SQL
    Hello,
    I have a simple report pulling data from two tables. I want
    only distinct records. I am selecting records based on
    parameters; here is the select formula:
    ({?Service Name} = "*" or {selsvc.ServiceName} like
    {?Service Name})and
    ({?Program Name} = "*" or {selsvc.Selected Service Entry 
    Program Name} like {?Program Name}) and
    ({?Agency Name}  = "*" or {selsvc.Selected Service Entry 
    Agency Name} like {?Agency Name})
    The problem comes from the fact that Crystal will add the
    selsvc fields to the reports SQL select code, which has the
    effect of duplicating some records that do not have the same
    values for the selsvc fields. The select formula above is
    the only place in the report where values from the selsvc
    field are used, and as you can see they are only used when
    the user has submitted a matching parameter for them. I can
    not figure out how to get rid of the duplicates, please
    help!
    Thanks for your time,
    Chris

    Post Author: yangster
    CA Forum: Data Connectivity and SQL
    I don't follow why you are getting duplicates with your selectionare you getting duplicates without the selection criteria?if you are then they really are not duplicates and there could be issues with your joins between the 2 tables

  • Distinct record help!

    Hi All,
    Hope you are doing great!
    I have the following query.
    SELECT DISTINCT DT.STD_ID STDID,
    UP.FIRST_NAME FIRSTNAME,
    UP.LAST_NAME LASTNAME,
    DT.TYPE ROLE,
    NVL2 (CT.USER_ID, 'Y', 'N') CKCTEAM,
    CT.USER_ID
    FROM DEAL D,
    DEAL_TEAM DT,
    CKC_TEAM CT,
    USER_PROFILE UP
    WHERE D.DEAL_ID = DT.DEAL_ID
    AND DT.STD_ID = UP.STD_ID
    AND D.DEAL_ID = 'D0002064';
    And the following result.
    STDID     FIRSTNAME LASTNAME ROLE     CKCTEAM     USER_ID
    V285773     MAHIA     ANNA     CREATEBY     Y     E067448
    E015989     JACQU     CARR     EDITOR     Y     E067448
    V285773     MAHIA     ANNA     BANKER     Y     E067448
    O256285     ALLA     OLWEN     EDITOR     Y     E067448
    I need the results to have distinct records based on the first name and last name irrespective of the roles. Now you can see from the result set that there is a duplicate record for "MAHIA     ANNA" since the user has 2 different roles.
    Appreciate your help on this.
    Thanks in advance
    MN

    Use query from my previous post, if you want to group your records only by names. Or this, if you want to group by all except role.
    SELECT DT.STD_ID STDID,
    UP.FIRST_NAME FIRSTNAME,
    UP.LAST_NAME LASTNAME,
    max(DT.TYPE) ROLE,
    NVL2 (CT.USER_ID, 'Y', 'N') CKCTEAM,
    CT.USER_ID
    FROM DEAL D,
    DEAL_TEAM DT,
    CKC_TEAM CT,
    USER_PROFILE UP
    WHERE D.DEAL_ID = DT.DEAL_ID
    AND DT.STD_ID = UP.STD_ID
    AND D.DEAL_ID = 'D0002064' group by DT.STD_ID,UP.FIRST_NAME, UP.LAST_NAME,CT.USER_ID;

  • How  to divide distinct records in a table into batches

    Hi all,
    I need a small help . I have some 3 to 4 lakhs of records in table . I want to divide these records into batches by assigning some batchno to some set of records. i.e i'll query some distinct records those distinct records should be assigned to one batchno . i.e when i query there may be some 100 records of one unique value in a column and 1000 next and so on . I want to make these records to one one batchno . Can any one help in this regard.
    Regards,
    rakesh

    May below given SQL help you...
    WITH T AS
    SELECT 'A' COL1 FROM DUAL UNION ALL
    SELECT 'B' COL1 FROM DUAL UNION ALL
    SELECT 'D' COL1 FROM DUAL UNION ALL
    SELECT 'A' COL1 FROM DUAL UNION ALL
    SELECT 'X' COL1 FROM DUAL UNION ALL
    SELECT 'P' COL1 FROM DUAL UNION ALL
    SELECT 'B' COL1 FROM DUAL
    SELECT COL1 , 'BTCH_'||DENSE_RANK() OVER (ORDER BY COL1) BATCH_NO
    FROM   T;
    COL1     BATCH_NO
    A     BTCH_1
    A     BTCH_1
    B     BTCH_2
    B     BTCH_2
    D     BTCH_3
    P     BTCH_4
    X     BTCH_5
    7 rows returned in 0.00 seconds     *009*

  • Convert comma delimed values to distinct records

    Hello,
    i wrote the following code to get the data from comma delimited row into distinct values to another table. say for example my data into column looks like this.
    long_string column data looks like this:
    11,12,14,16,13,18,17
    11,12,13,15,16,17,18,19,20,30
    11,20,30,40,67,90,87,65,76,43,23,56,78,90,12,22,34 - which doesn't have a comma at the end of the data.
    i need to convert this into distinct record for each rows data.
    i used mod function...
    can some one help me.
    DECLARE
    cursor c_1 is select LONG_STRING from TEST;
    rec c_1%rowtype;
    temp_VAR varchar2(100);
    size_of_VAR number;
    number_of_VAR number;
    i number;
    cur_VAR varchar2(3);
    begin
    open c_1;
    loop
    fetch c_1 into rec;
    exit when c_1%notfound;
    temp_VAR := rec.LONG_STRING;
    size_of_VAR := length(temp_VAR);
    number_of_VAR := size_of_VAR/4;
    if (mod (size_of_VAR,4) = 0) then
    for i in 1..number_of_VAR loop
    cur_VAR:=substr(temp_VAR,1,3);
    INSERT INTO TEST_ST (LONG_ST_NUM)
    VALUES ( cur_VAR);
    temp_VAR:= substr(temp_VAR,5);
    end loop;
    else
    dbms_output.put_line('Rules problem for LONG_STRING: ' || rec.LONG_STRING);
    end if;
    end loop;
    close c_1;
    end;
    Thanks...

    Ah, I see, I took my requirement from the later posters as it wasn't clear from OP. It's not the aggregation problem that Listagg solves, but the inverse, disaggregation. I don't know a direct equivalent SQL function, but not to worry, it seems my weekend effort on another thread wasn't wasted because I can see a very simple variation on one of the solutions there that will solve this one very efficiently. It uses the model clause to iterate over the commas without any regular expression functions, XML, tree walks etc. to slow it down, and this approach should work for many similar problems. I'll add an id column so we know where the rows came from and a subid for ordering (you can drop them if you like), and an extra test record with no comma.
    CREATE TABLE test_otn  (id INTEGER, text VARCHAR2(4000));
    INSERT INTO test_otn VALUES (1, '11,12,14,16,13,18,17');
    INSERT INTO test_otn VALUES (2, '11,12,13,15,16,17,18,19,20,30');
    INSERT INTO test_otn VALUES (3, '99');
    INSERT INTO test_otn VALUES (4, '11,20,30,40,67,90,87,65,76,43,23,56,78,90,12,22,34');
    SELECT id, numid, num
      FROM test_otn
    MODEL
        PARTITION BY (id)
        DIMENSION BY (0 i)
        MEASURES (0 compos, 0 nxtpos, text, 0 numid, CAST ('' AS VARCHAR2(5)) num)
        RULES
        ITERATE (100) UNTIL compos[0] = 0
           nxtpos[0] = Instr (text[0], ',', compos[0] + 1, 1),
           num[ITERATION_NUMBER] = CASE WHEN nxtpos[0] = 0 THEN Substr (text[0], compos[0]+1)
                                        ELSE Substr (text[0], compos[0] + 1, nxtpos[0] - compos[0] - 1) END,
           numid[ITERATION_NUMBER] = ITERATION_NUMBER + 1,
           compos[0] = nxtpos[0]
    ORDER BY 1, 2
      ID      NUMID NUM
       1          1 11
                  2 12
                  3 14
                  4 16
                  5 13
                  6 18
                  7 17
       2          1 11
                  2 12
                  3 13
                  4 15
                  5 16
                  6 17
                  7 18
                  8 19
                  9 20
                 10 30
       3          1 99
       4          1 11
                  2 20
                  3 30
                  4 40
                  5 67
                  6 90
                  7 87
                  8 65
                  9 76
                 10 43
                 11 23
                 12 56
                 13 78
                 14 90
                 15 12
                 16 22
                 17 34
    35 rows selected.

  • Distinct Records Selection in Crystal 11

    Need to select Distinct Records only, but the drop down under 'Database' shows the 'Select Distinct Records' option grayed out.  Why does Crystal do that, and how may I eliminate duplicate records?  Thanks!

    Hi Brian,
    This issue normally comes when there are multiple datasources being used. For example if you are using two databases, like Oracle and MS Access to fetch data, the "Select Dictinct Records" will be greyed out.
    In this case, you might want to write a query in the Add Command option which select distinct records.
    If you are using only one database, then check if you are able to select "Select Dinstinct Records" in the Database menu.
    Please let us know if this helps.
    Regards,
    Abhishek.

  • Get Distinct records with a condition

    I have a table with multiple records per Person and an active status column. I would like to fetch distinct records by PersonID and PersonName but also return active status with a condition that if person is active on at least one he is considered active.
    Here is my table.
    DECLARE @Person TABLE (PersonID INT, PersonName VARCHAR(50), DeptName VARCHAR(50), Active bit)
    INSERT INTO @Person (PersonID, PersonName, DeptName, Active) VALUES (111, 'John', 'Finance', 0), (111, 'John', 'HR', 1),(222, 'Jack', 'Payroll', 0),(333, 'Mark', 'Facilities', 1),(444, 'Bill', 'IT', 0),(444, 'Bill', 'HR', 1),(444, 'Bill', 'Finance', 1)
    My resultset after the query should be as follows.
    (111, 'John', 1),(222,'Jack',0),(333,'Mark',1),(444,'Bill',1)
    Thanks for the help.

    >> I have a table with multiple records [sic] per Person and an active status column. <<
    Rows are not records. Tables have to have a key by definition and since they model a set, the names are plural or collective. These are fundamentals that were covered in the first few chapters of any book on RDBMS. You do not know ISO-11179 naming rules. 
    You still use assembly language bit flags in SQL! A status is a state of being so it requires a temporal component. Do you really know people with FIFTY character name? Even in Poland and India, that is not likely. But when you allow garbage data, you will
    get it. 
    Identifiers are CHAR(n), not numeric; what math do you do with them? Again, this is a fundamental of data modeling. 
    You are simply reenforcing your bad habits and not taking the time to learn how to do RDBMS correctly. 
    CREATE TABLE Personnel --- collective name!
    (person_id CHAR(3) NOT NULL,
     person_name VARCHAR(10) NOT NULL, 
     dept_name VARCHAR(10)NOT NULL, 
     hire_date DATE NOT NULL,
     termination_date DATE,
     CHECK (hire_date < termination_date),
     PRIMARY KEY (person_id, hire_date));  -- null means current.
    See how a valid design makes finding a status possible? And it shows us just what a mess you have! Bill is working in TWO departments! See how the key prevents this error? We should add more constraints, but I do not think you are ready for that yet. 
    SELECT person_id, person_name, dept_name AS current_dept_name
      FROM Personnel 
     WHERE termination_date IS NULL;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • Crack sound Macbook Air 2013

    Hello, i've got a problem(if we can call it) with my Macbook Air 2013(bought on july 2013). when i type,i usually put my hands on the surface right next to the pad. i do not apply any forces or put all the weight on the surface but it sounds like a c

  • Confused by multiple versions of Creative Cloud apps

    I now have Photoshop CC, Photoshop CC (2014), Muse CC, and Muse CC 2014 installed on my machine and listed in my creative cloud applet. The Creative Cloud applet says they are all up to date. I am presuming that the versions with (2014) appended to t

  • Ttf files not appearing

    Hi, I keep downloading zip files from sites like dafont to install some fonts, but when I download the zips and open them with archive manager I find nothing inside them. I even copied some over from my Ubuntu partition that did have them in and when

  • HT1918 Changing country with credit

    How do I change my country while I still have store credit in another country, all beit $0.03 Thanks

  • Language data type problem

    I am executing a FM from XI to create a Material with several languages in the form of ES, EN, FR and so on, what is the type that I have to use in the FM for this languages? I use a simple Char 2 type and does not work from XI but If I use SPRAS wor