Summing decode amount

Now that you helped me solve a total problem in a crosstab report I have run into another problem in the same report.
Given are three of the columns A,B,C in the crosstab report .
A & B are fields from the folders.
C is a calculated field: NVL(DECODE(AccountType,'Income',( DECODE(Cc Concatenated Segments,MAX(Cc Concatenated Segments) OVER(PARTITION BY AccountType ),Surplus Budget,0) ),0),0)
C gives me exactly what I want which is a total in only one of the fields while all the rest are 0. (I think that the reasoning as to why I need that is not relevant here). I do not get a total of Field C (it's always blank) but the user is fine with that.
My problem is that that there needs to be another field D = C - A + B and I do need the grand total of that Field D.
The total is always blank. I have tried using to_number and multiplying the fields by 1.0. I have tried defining a new field that is C * 1.0 in order to make sure that it is a number. The AggregationBehavior is 1 as is the AllowAggregationOverRepeatedValues, but the total will always be blank.
If I remove field C from the calculation then it gives me the sum. In other words Field C is definitely the problem.
Is this total even possible?
Thanks.
Leah

Hi Leah
It can be daunting at first but practice makes perfect. I have an extremely analytical brain and I have been lucky to have the ability to extend a calculation by 2 or even 3 steps away from where it currently stands. Most people can generally only accept ideas that are one step away from what they know already. Moving two or three steps away without explaining how it is done loses some people and they generally get cross. What I'm getting at is that moving too many analytic steps at the same time is fraught with danger until the basic calculations are fully understood and no erroneous answers pop out.
Embedding analytic functions inside other functions is a perfect example of moving more than one step at the same time, thus breaking it down into its atomic parts generally does the trick and the answer usually becomes obvious. I appreciate that I am teaching statistical theory and please forgive me if I get too deep. My major was mathematics and sometimes I get carried away.
You asked whether MAX has to take a number. The answer if no. It does not have to take a number. You can compute the max of a number, a string or a date. Certainly if you have a MAX calculation embedded into a DECODE that under one set of circulstances produces a number and in another set produces a string then the results may not be what you expect.
Is the DescrField supposed to contain a number or a string? If it contains numbers but they are stored as strings then the MAX of a set of strings will not always produce the same result as the max of a set of numbers.
I certainly think you need to break down your formulas into manageable single calculations with separate calcs joining them together.
Hang on in there because you will find it. It sounds as though you may already have hit on something.
Best wishes
Michael

Similar Messages

  • SUM THE AMOUNT WITHOUT USING THE OVER COMMAND

    hi 2 everybody......
    the table contains:
    uid billno amount
    1 101 100
    2 102 200
    3 103 300
    the o/p shuld be:
    uid billno amount total
    1 101 100
    2 102 200 300
    3 103 300 600
    i need the query for this pblm without using the over command... please advice... can anyone send immed... thanks in advance...

    So you still don't bother to write in proper understandable English or probably your keyboard is broken.
    Any way you can do this
    SQL> WITH t AS (
      2  SELECT 1 col_uid, 101 billno, 100 amount FROM DUAL UNION ALL
      3  SELECT 2, 102, 200 FROM DUAL UNION ALL
      4  SELECT 3, 103, 300 FROM DUAL)
      5  -- end test data
      6  select col_uid, billno, amount, decode(amount, amount_cum, null, amount_cum) amount_cum
      7    from (
      8  select t.*, (select sum(amount) from t t1 where t1.col_uid <= t.col_uid) amount_cum
      9    from t)
    10  /
       COL_UID     BILLNO     AMOUNT AMOUNT_CUM
             1        101        100
             2        102        200 300
             3        103        300 600

  • SUM(DECODE(.................) in OWB???

    We have a materialized view that along with other statements has:
    Select SSN,...,...,
    SUM(DECODE(Depn_info_relationship_code,Null,0,1) Num_dependents,
    SUM(DECODE(Depn_info_relationship_code,'AO',1,0) Spouse,
    etc.
    I have been unable to create this in OWB. Any help greatly appreciated.

    Eric,
    You can create a materialized view in 2 ways:
    - write the query manually, which would be easy, I supposse.
    - use the mapping editor to build a materialized view and eventually do a reconcile outbound. In that case, you use mapping operators to define the query. You can use the expression operator to define... a CASE statement (instead of the decode) and cascade using the aggregator. Eventually reconcile outbound to the materialized view.
    Hope this helps,
    Mark.

  • Sum & decode function

    i have three products viz :'A' ,'B' ,'C'
    I WANT THE OUTPUT LIKE
    PARTY NAME A B C APR04 A B C MAY04 TOTAL
                             A B C
    XYZ LTD     10 11 11 32 15 4 2 21 25 15 13
    YYY LTD 05 0 5 10 25 8 2 35 30 08 07
    I WANT TO TAKE SUCH OUTPUT FROM APR04 TO MAR05 .
    I TRIED SOMETHING LIKE THIS
    SELECT
    invo_h.PTYCD,PARTY_M.PARTY_N1,
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',invo_d.QNTY,0)) APR_04,
    sum(decode(invo_d.prdcd,'A',invo_d.QNTY,0)) "A",
    sum(decode(invo_d.prdcd,'B',INVO_D.QNTY,0)) "B",
    sum(decode(invo_d.prdcd,'C',INVO_D.QNTY,0)) "C",
    sum (INVO_D.QNTY) "TOTAL",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',invo_d.QNTY,0)) MAY_04,
    sum(decode(invo_d.prdcd,'A',invo_d.QNTY,0)) "A",
    sum(decode(invo_d.prdcd,'B',INVO_D.QNTY,0)) "B",
    sum(decode(invo_d.prdcd,'C',INVO_D.QNTY,0)) "C",
    sum (INVO_D.QNTY) "TOTAL"
    FROM INVO_H,INVO_D,PARTY_M
    WHERE INVO_H.INVNO=INVO_D.INVNO
    AND INVO_H.INVDT BETWEEN '01-APR-04' AND '31-MAR-05'
    AND INVO_H.PTYCD=PARTY_M.PARTY_CD
    GROUP BY INVO_H.PTYCD,PARTY_M.PARTY_N1
    BUT IT IS GIVING WRONG OUTPUT. same figures even for month May-04 .
    PLS HELP

    SELECT
    invo_h.PTYCD,PARTY_M.PARTY_N1,
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',invo_d.QNTY,0)) APR_04,
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',decode(invo_d.prdcd,'A',invo_d.QNTY,0),0)) "A",
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',decode(invo_d.prdcd,'B',INVO_D.QNTY,0),0)) "B",
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',decode(invo_d.prdcd,'C',INVO_D.QNTY,0),0)) "C",
    sum (INVO_D.QNTY) "TOTAL",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',invo_d.QNTY,0)) MAY_04,
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',decode(invo_d.prdcd,'A',invo_d.QNTY,0),0)) "A",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',decode(invo_d.prdcd,'B',INVO_D.QNTY,0),0)) "B",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',decode(invo_d.prdcd,'C',INVO_D.QNTY,0),0)) "C",
    sum (INVO_D.QNTY) "TOTAL"
    FROM INVO_H,INVO_D,PARTY_M
    WHERE INVO_H.INVNO=INVO_D.INVNO
    AND INVO_H.INVDT BETWEEN '01-APR-04' AND '31-MAR-05'
    AND INVO_H.PTYCD=PARTY_M.PARTY_CD
    GROUP BY INVO_H.PTYCD,PARTY_M.PARTY_N1

  • Query to update T1.TotalAmount from sum(T2.Amount)

    I have 2 tables T1 and T2 such that
     T2.TotalAmount=sum(T1.Amount) where T1.BillType=T2.BillType and T1.BillNo=T2.BillNo  
    as shown below
    Table T1
    BillType
    BillNo
    ItemName
    Amount
    Sale
    156
    Rice
    100
    Sale
    156
    Vegetables
    20
    Purchase
    13
    Rice
    50
    Purchase
    13
    Vegetables
    10
     Table T2
    BillType
    BillNo
    TotalAmount
    Sale
    156
    120
    Purchase
    13
    60
    i have updated T1 with query 
    update T1 set Amount=Amount+100
    BillType
    BillNo
    ItemName
    Amount
    Sale
    156
    Rice
    200
    Sale
    156
    Vegetables
    120
    Purchase
    13
    Rice
    150
    Purchase
    13
    Vegetables
    110
    now i want to update T2.TotalAmount  with new values of T1.Amount such that
    T2.TotalAmount=sum(T1.Amount) where T1.BillType=T2.BillType and T1.BillNo=T2.BillNo 
    as shown below
    BillType
    BillNo
    TotalAmount
    Sale
    156
    320
    Purchase
    13
    260
    i tried this query
    update T2 set TotalAmount=(select sum(Amount) from T1 inner join T2 on T1.BillType=T2.BillType and T1.BillNo=T2.BillNo where T1.BillType=T2.BillType and T1.BillNo=T2.BillNo)
    this returned table T2 as below
    BillType
    BillNo
    TotalAmount
    Sale
    156
    580
    Purchase
    13
    580
    What should i do to get T2.TotalAmount correctly

    Try this: (not tested)
    update T2 set T2.TotalAmount= O.TotalAmount From T2 Inner join
    (select BillType,BillNo,sum(Amount) As TotalAmount from T1 Group by BillType,BillNo ) O on O.BillType = T2.BillType and O.BillNo = T2.BillNo
    Thanks
    Bharath

  • Sum an amount between a certain date range

    Hello,
    I am working out a home budget and want to know how to calculate what is due this month.
    I have two columns - "Amount" and "Due Date". Some content for an example is:
    Amount,Due Date
    20,15/05/2009
    300,16/05/2009
    40,1/06/2009
    What I want is a formula which will sum the total amount of items due within this months' date range. If the date range could be as automatic as "This Month" that would be great otherwise I would say IF "Due Date" between 1/05/2009 and 31/5/2009.
    Is this possible?

    In column D, the formula is:
    =YEAR(C)*100+MONTH(C)
    In B8 and in B9 the formula is:
    =SUMIF(D,YEAR(A)*100+MONTH(A),B)
    Yvan KOENIG (from FRANCE jeudi 14 mai 2009 15:30:56)

  • Sum of amounts from the previous years

    How do i calculate Sum of the value of invoice amounts paid for the FY 3 years prior to the current year.I tried LAG but its not giving me the desired results.
    Thanks

    Hi
    You have to understand how LAG works then you'll be able to do it.
    LAG works back looking at a set of sorted data, using the PARTION BY and ORDER BY clauses, then pulls a value from x rows preceding. All the data that you want must be in the worksheet too so you must not be filtering on current year.
    Here's what I do:
    I take a copy of the worksheet I am working with and look at the data in tabular form. Then I use one or more Group Sorts to pull like items together. These will become my PARTITION BY clauses. Any specific sorting, such as the year come next - these become the ORDER BY clause.
    Finally, from where you are in one row you look to see how many rows away is the data that you want and you add that as the final piece of the LAG function.
    You then test out the LAG function in the table before moving it into the real worksheet.
    Does this help?
    Best wishes
    Michael

  • How to Sum the amounts for calculating rates.

    Hi,
    I have a requirement in Apps 11i (OAB) that I need to code in PL/SQL. I would be calling a procedure in order to complete this task. When an Extract is run, this code gets executed and should return the amount for that person.
    I need to calculate sum of all the amounts for each of the months between START date to the END date.
    Ex: Amount = Amount + (for each of the months between START and END date) x Rate.
    This START and END date would be calculated in the procedure itself.(dynamic).
    Once we get the START date and END date, we need to loop thru some records and find person's rate between those START date and END date.
    For rate calculation:
    15th day of any month is used as the cut off date for rate calculation.
    Suppose from 01-JAN-2006 to 15-MAR-2006 Rate is Rs 10 AND
    16-MAR-2006 to 01-JUL-2006 rate is Rs 20 AND person died on 01-JUL-2006
    Then rate = Rs(3x10) + Rs(3x20) + full month of July Rs.20 (P.S Here person's death needs to evaluated for the whole month) =30 + 60 + 20 = Rs.110
    Typically the start date and end date would be in one particular YEAR. And person may have different rates for different amounts as mentioned above.
    Let me if you need any more details..Thank You!
    Additional Info:
    This data comes from 2 tables in OAB Application where it can be joined with a common ID.
    One table lets say Coverage table contains the usual columns Eff_start_date, Eff_end_date along with this it has Coverage_start_date and Coverage_end_date (Dates specifying duration of the person enrolled in particular coverage.)
    P.S Rate Changes ONLY when the person enrolls in different coverage.
    2nd Table lets say Rate table contains the usual columns Eff_start_date, Eff_end_date along with this it has rate_start_date and rate_end_date and RATE(column) for that duration.(may vary depending upon the coverage).
    All the records should be between the START and END date, which will be calculated at runtime.
    Unable to submit any sample records.:-(
    Well, IF I had given the exact requirement, I would have got the solution by this Time!!! Your comments (and solutions) would definitely help me. Thank You
    Message was edited by:
    user559682

    If i understand you correctly it can be possible with :
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> drop table dates;
    Table dropped
    SQL> create table dates( "start" date, "end" date, "rate" number);
    Table created
    SQL> insert into dates values( to_date('01.01.2006', 'DD.MM.YYYY'), to_date('30.05.2006', 'DD.MM.YYYY'), 10);
    1 row inserted
    SQL> insert into dates values( to_date('01.06.2006', 'DD.MM.YYYY'), to_date('15.09.2006', 'DD.MM.YYYY'), 15);
    1 row inserted
    SQL> insert into dates values( to_date('16.09.2006', 'DD.MM.YYYY'), to_date('31.12.2006', 'DD.MM.YYYY'), 20);
    1 row inserted
    SQL> SELECT * FROM dates;
    start       end               rate
    01.01.2006  30.05.2006          10
    01.06.2006  15.09.2006          15
    16.09.2006  31.12.2006          20
    SQL> SELECT t.i, d."rate"
      2    FROM (SELECT add_months(to_date('01.01.2006', 'DD.MM.YYYY') /* start*/, LEVEL - 1) i
      3            FROM dual
      4          CONNECT BY LEVEL <= 12) t
      5        ,dates d
      6   WHERE t.i BETWEEN d."start" AND d."end";
    I                 rate
    01.01.2006          10
    01.02.2006          10
    01.03.2006          10
    01.04.2006          10
    01.05.2006          10
    01.06.2006          15
    01.07.2006          15
    01.08.2006          15
    01.09.2006          15
    01.10.2006          20
    01.11.2006          20
    01.12.2006          20
    12 rows selected
    SQL> SELECT SUM(d."rate") rs
      2    FROM (SELECT add_months(to_date('01.01.2006', 'DD.MM.YYYY') /* start*/, LEVEL - 1) i
      3            FROM dual
      4          CONNECT BY LEVEL <= 1 +
      5                     extract(MONTH FROM to_date('10.10.2006', 'DD.MM.YYYY') /*death*/) -
      6                     extract(MONTH FROM to_date('01.01.2006', 'DD.MM.YYYY') /* start*/)
      7          ) t
      8        ,dates d
      9   WHERE t.i BETWEEN d."start" AND d."end";
            RS
           130
    SQL>

  • Validations on table control (Sum of amount field shuold not cross actual amaount))

    Hi Experts,
                      I want to Provide Validations on Table control with Wizard (it should be like when i enter  percentange  in one column  it will caluculate the amount and show it in another column and the sum of that Amount Should not cross the Actual amount).

    hi Jim,
    In the PAI of the Screen A ...
    when sy-ucomm = 'BACK'.
    Transfer  the values in the table control to an internal table itab.
    in the PBO of Screen B.
    Move the values in itab to table control.
    Thanks,
    Kasiraman R

  • Testing sum of amounts in body by mapping

    hi.
    here in my scenario i have to sum all individual amounts in sender file and i have to compare with trailer sum.
    for this i have created my sender mtype amount and  i have checked with sum(statistical function) and i compared with trailer info.
    its working with integers but when there are amounts with decimals then the sum is not showing correct value.
    im my scenario the sum is supposed to be 40843.55 but the sum(statistic function) is showing like 40843.555.
    can any body tell what changes i have to do for this.
    waiting for u r well anser.
    regards.
    seeta ram.

    try;
    public void chkAmountSum(String[] a,String[] b,ResultList result,Container container){
    //write your code here
    double tempAmt = 0;
    double tempSum = 0;
    double tempRes = 0;
    double temp = 0;
    double count = 0;
    try{
    for (int j = 0; j<a.length; j++)
        temp =Double.parseDouble(a[j]);
        tempAmt = tempAmt + temp ;
    for (int j = 0; j<b.length; j++)
    tempSum = Double.parseDouble(b[j]);
    tempRes = tempAmt - tempSum;
    if (tempRes != 0)
      a[0] = "Not equal";
      result.addValue(a[0]);
    else
      a[0] = "Is Equal";
      result.addValue(a[0]);
    }catch(NumberFormatException e)
    a[0] = "Exception";
    result.addValue(a[0]);

  • How to sum the amount

    how can I add the amount shown below for year 1999. I would like to add all the amount between 01/22/1999 - 12/17/1999. thank you
    here is my simple sql looks like
    select sum(l.contamt),b.datelet
    from bidlet b, letprop l
    where b.LETTING = l.LETTING
    and l.LETSTAT='A'
    group by b.datelet
    Here is my desired out put
    Amount year
    xxxxxx 1999
    xxxxx 2000
    xxxxxx 2001
    24,692,441     01/22/1999 00:00:00
    30,625,058     02/26/1999 00:00:00
    810,879     03/16/1999 00:00:00
    45,415,715     03/19/1999 00:00:00
    34,359,502     04/09/1999 00:00:00
    34,967,761     04/23/1999 00:00:00
    1,396,831     05/04/1999 00:00:00
    40,408,333     05/14/1999 00:00:00
    37,556,062     05/28/1999 00:00:00
    19,583,374     06/11/1999 00:00:00
    45,105,742     06/25/1999 00:00:00
    6,096,878     07/23/1999 00:00:00
    369,439     08/17/1999 00:00:00
    15,293,129     08/27/1999 00:00:00
    9,249,995     09/10/1999 00:00:00
    9,078,176     09/24/1999 00:00:00
    2,153,323      10/22/1999 00:00:00
    6,239,335     11/19/1999 00:00:00
    26,908,007     12/17/1999 00:00:00

    user452051 wrote:
    how can I add the amount shown below for year 1999.You're very nearly there - all you need to do is convert your dates so they all represent just the year part - you can do this by using the TRUNC function to set the dates to the start of whatever year they belong to:
    eg.
    TRUNC(sysdate, 'yyyy')

  • Sum of amount field in the Query

    Hello folks,
    I have a amount field in the query, along with the amount field I also need to show sum of all the rows for this amount fields, can some one guide which is best way of doing it?
    Thanks,
    KK

    Thanks for the response's...Rama, Prasad and Sandesh!
    I have changed the Property of the Amount field (SAP Standard Infoobject) to Calculated Result as 'Summation' but when I tried to save the changes in Query designer I am getting following error
    runtime error '91'
    Object variable or with block variable not set
    runtime error '4XX'
    ActiveX component can't create object
    And its disconnecting from BEX Server...how can I resolve this error?
    Thanks,
    KK
    Edited by: kumar K on Aug 21, 2008 10:46 AM

  • Is it possible to sum up amounts in report scripts?

    Hi - is this possible? If so, can you give me an example? I have not been able to find a commend for this. I am using Essbase 6.5
    I have a cost center with many accounts. I need to pull that cost center and sum up the accounts into one number. the accounts do not all belong under 1 parent.
    Thanks
    Edited by: CLAU on Nov 11, 2009 1:47 PM

    The commands Gary gave you are valid for 6X versions. But I would wonder why you are not creating a rollup in accounts that sums your accounts and then pulling that member. It seems like this would be something that would be used often
    CLAU are you a consultant or do you work for a company? your profile says Essbase developer, but that is pretty vague.
    Edited by: GlennS_2 on Nov 11, 2009 4:58 PM

  • Sum amount - Positive and negative

    How do I have a select statement that sum up all the negative and positive values into 2 serperate column? sth like this:
    SELECT sum(amount) as negative, sum(amount) as positive FROM account_table WHERE customer_id = 111;Here is how the output look like when I retrieve the amount of customer_id = 111:
    Amount
    1.4
    300
    -1.22
    -100The expected output that I want should be like this:
    Positive          Negative
    301.4                -101.22

    DECODE and SIGN functions can help
    SQL> select * from t
      2  /
           VAL
             1
            -2
             3
            -4
             5
            -6
             7
            -8
             9
           -10
    10 rows selected.
    SQL> select sum(decode(sign(val),1,val)) pos, sum(decode(sign(val),-1,val)) neg
      2    from t
      3  /
           POS        NEG
            25        -30

  • Query takes much time while sum of yearly bases amount

    I have made query on the basis of joing to get payroll data it's woking fine but when we accumulate this on yearly basis while giving parameter from and to date then it takes much time, so how can we optimise this.
    please advice.

    this is query
    SELECT paa.assignment_id,MAX(EFFECTIVE_DATE) effective_date,
    paypa.business_group_id,paypa.payroll_id,
    nvl(SUM(decode(pet.element_type_id,10,decode(pivf.name,'Pay Value',TO_NUMBER(NVL(prrv.result_value, 0))))),0) AMOUNT
    FROM pay_assignment_actions paa,
    pay_payroll_actions paypa,
    pay_run_results prr,
    pay_element_types_f pet,
    pay_element_classifications pec,
    pay_run_result_values prrv,
    pay_input_values_f pivf
    where paypa.payroll_ACTION_id = paa.payroll_ACTION_id
    AND prr.assignment_ACTION_id = paa.assignment_ACTION_id
    AND paypa.action_status = 'C'
    AND paa.action_status = 'C'
    and paypa.action_type in ('Q','R')
    AND pet.element_type_id = prr.element_type_id
    AND pec.classification_id = pet.classification_id
    AND pivf.input_value_id=prrv.input_value_id
    AND prr.run_result_id = prrv.run_result_id
    AND pivf.element_type_id = pet.element_type_id
    AND paypa.effective_date BETWEEN pivf.effective_start_date AND pivf.effective_end_date
    AND paypa.effective_date BETWEEN pet.effective_start_date AND pet.effective_end_date
    AND paypa.effective_date between to_date('01-JUL-2010') AND TO_DATE('30-JUN-2011')
    group by paa.assignment_id,paypa.business_group_id,paypa.payroll_id
    any idea for this ,how can we improve performance,althoug it's woking fine without using group by function
    Edited by: oracle0282 on Mar 31, 2011 11:36 PM

Maybe you are looking for

  • How come my Nikon D610 can not open photoshop CS6 raw files

    any one know,i just bough a New Nikon D610 digitalcamera, i am upload in to Photoshop CS6 raw file, but can not open,why?

  • NO AUDIO ON BATCH EXPORT.  First 2 times i posted this it never showed up....

    Why do I randomly get audio from batch export using AME.  Usually it doesn't work at all as in NO audio but other times several of the files in a batch will have audio.  And other times none. What gives? running Mavericks on G5 with 12GB of RAM and Q

  • Incorrect Fonts When "Printing" Webpage to .pdf

    When I "print" a webpage to a .pdf file, I occasionally get an incorrect font.  For example, if I print a Wikipedia page, the font in the saved file will be Times New Roman.  The font on the webpage looks to be Arial.  I'm assuming it is a setting in

  • Document Color Mode

    Is there any option to change the document color mode as we can change in Illustrator

  • About EJB 3.0 ?

    i don't know anything about EJB (nither EJB 3.0 nor any previous version ) i want to learn EJB 3.0, but the final version of 3.0 EJB 3.0 has not been release. i have heard that in EJB 3.0 all the old concepts have been changed. a) will it be a good i