Query help , calculating Cummulative totals

Hi,
I have a table data_set in which we have the income amounts on month to month basis. I want to update the same table to populate the cummulative total fields for the current month's income + previous months cummulative total. Below is the sample data.
I am using 10.2.0.1.0 ( 10g) and want to write an update statement to update the fields.
with data_Set as(
select '201001' month, '1000' income_amt, '1000' net_income_amt, null cumulative_income_Amt, null cumulative_net_income_amt from dual union all
select '201002' month, '1100' income_amt, '1000' net_income_amt,null,null from dual union all
select '201003' month, '1200' income_amt, '1000' net_income_amt,null,null from dual
) select * from data_SetWrite an update statement so the table looks like below
with data_set as (
select '201001' month, '1000' income_amt, 1000  cumulative_income_amt, '1000' net_income_amt, 1000 cumulative_net_income_amt from dual union all
select '201002' month, '1100' , 2100,   '1000' , 2000 from dual union all
select '201003' month, '1200' , 3300,   '1000' , 3000 from dual
) select * from data_setEdited by: user527060 on Oct 29, 2010 12:03 PM
Edited by: user527060 on Oct 29, 2010 12:04 PM

/* Formatted on 10/29/2010 3:18:42 PM (QP5 v5.149.1003.31008) */
WITH data_Set AS (SELECT '201001' month,
                         '1000' income_amt,
                         '1000' net_income_amt,
                         NULL cumulative_income_Amt,
                         NULL cumulative_net_income_amt
                    FROM DUAL
                  UNION ALL
                  SELECT '201002' month,
                         '1100' income_amt,
                         '1000' net_income_amt,
                         NULL,
                         NULL
                    FROM DUAL
                  UNION ALL
                  SELECT '201003' month,
                         '1200' income_amt,
                         '1000' net_income_amt,
                         NULL,
                         NULL
                    FROM DUAL)
SELECT month,
       income_amt,
       SUM (income_amt) OVER (ORDER BY month) cumulative_income_amt,
       net_income_amt,
       SUM (net_income_amt) OVER (ORDER BY month) cumulative_net_income_amt
  FROM data_Set;
MONTH,INCOME_AMT,CUMULATIVE_INCOME_AMT,NET_INCOME_AMT,CUMULATIVE_NET_INCOME_AMT
201001,1000,1000,1000,1000
201002,1100,2100,1000,2000
201003,1200,3300,1000,3000sorry I originally missed the part where you wanted to update here it is with merge
/* Formatted on 10/29/2010 3:26:26 PM (QP5 v5.149.1003.31008) */
MERGE INTO data_set a
     USING (SELECT month,
                   income_amt,
                   SUM (income_amt) OVER (ORDER BY month)
                      cumulative_income_amt,
                   net_income_amt,
                   SUM (net_income_amt) OVER (ORDER BY month)
                      cumulative_net_income_amt
              FROM data_Set) b
        ON (a.month = b.month AND a.income_amt = b.income_amt and a.net_income_amt = b.net_income_amt)
WHEN MATCHED
THEN
   UPDATE SET
      a.cumalative_income_amt = b.cumulative_income_amt,
      a.cumulative_net_income_amt = b.cumulative_net_income_amtEdited by: pollywog on Oct 29, 2010 3:26 PM
Edited by: pollywog on Oct 29, 2010 3:29 PM

Similar Messages

  • Bucket query help

    create table rangespendbucket(rangespend varchar2(40), id number)
    insert into rangespendbucket values('100-200',1);
    insert into rangespendbucket values('200-500',2);
    insert into rangespendbucket values('500-1000',3);
    insert into rangespendbucket values('1000-',4);
    commit;
    create table spend(supplier varchar2(40), cy_spend number)
    insert into spend values('A',100);
    insert into spend values('B',25);
    insert into spend values('C',30);
    insert into spend values('D',1000);
    insert into spend values('E',10);
    insert into spend values('A',200);
    insert into spend values('F',0);
    insert into spend values('E',20);
    insert into spend values('C',540);
    insert into spend values('B',300);
    insert into spend values('A',300);
    insert into spend values('C',10);
    insert into spend values('B',0);
    insert into spend values('E',0);
    insert into spend values('G',90);
    insert into spend values('H',0);
    insert into spend values('A',0);
    insert into spend values('P',7000);
    commit;
    i am new in this forums . some one in my company given me the following query/task.
    I want find out all those in a single query(1-8) except 1.1(separatee query).
    we are using oracke 10g reaalese 2 version.
    1)no of customer/supplier in the spend bucket.
    1.1. If anybody clcik on that particular bucket it will show no of suppliers.
    2)total no of supplier for all bucket(sum)
    3)% of supplier for each bucket.(each bucket supp cnt *100/total supp cnt)
    3)total spend for each bucket
    4)total spend for all combination of bucket
    5)% of spend for each bucket than total bucket(each bucket supp spend *100/total supp spend)
    6)how many no of suppliers make 80% of total spend(respect to all bucket)
    7)how many no of suppliers make 20% of total spend(respect to all bucket)
    8)top 3 suppliers make how much % of spend(respect to all bucket)
    i am eagerly requesting to all of you please help me to making this query.
    this query is required for making dashboard.
    column name should be like this-totalsupplierscnt__all_bucket,'cnt suppliers 100-200','%cnt suppliers 100-200','cnt supplier 200-500','%cnt supplier 200-500',
    'cnt supplier 500-1000','%cnt supplier 500-1000','cnt suppliers 1000-','%cnt suppliers 1000-',
    totalsuppliersspend_all_bucket,'spend for 100-200','%spend for 100-200','spend for 200-500','%spend for 200-500',
    'spend for 500-1000','%spend for 500-1000','spend for 1000-','%spend for 1000-',
    'no of supplierss 80% of total spend'(calculation-suppose total spend 100. spend sorted by decending 80% of total spend may cover 1-2 suppliers),
    'no of supplierss 20% of total spend'(calculation- total no of suppliers- no of suppliers making 80% spend),
    'top 3 suppliers spend'(calculation-spend sorted by desc,if we get total spend then we calculate -top3'spend*100/total spend)
    if you want much more clarification i will give you.
    Edited by: 949497 on Jul 27, 2012 7:51 PM
    Edited by: 949497 on Jul 27, 2012 8:11 PM

    Hi,
    Welcoem to the forum!
    949497 wrote:
    create table rangebucket(rangespend varchar2(40), id number) ...Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful!
    i am new in this forums ....You're way ahead of some people, who have been using the forum for years but still haven't learned how to post their data.
    Don't forget to post the exact results you want from that data.
    How are the two tables related? Do you have to parse rangebucket.rangespend to extract the NUMBERs 100 and 200 from the VARCHAR2 '100-200'? It would be simpler to do it the other way around: store the NUMBERs 100 and 200 in two separate NUMBER columns, and derive the label '100-200' from them (or store the label in a separate column, as it is now, in addition to rangebegin and rangeened NUMBER columns).
    Whatever number is related to these ranges, what happens if that number is exactly 200? What if it is less than 100?
    >
    I want find out all those in a single query(1-8) except 1.1(separatee query).
    we are using oracke 10g reaalese 2 version.Thanks! That's another thing that's always imoportant (and another thing some people haven't learned to do).
    1)no of customer/supplier in the spend bucket.
    1.1. If anybody clcik on that particular bucket it will show no of suppliers.This is the SQL and PL/SQL forum. What do you mean by "click", and how does it involve SQL or PL/SQL?
    2)total no of supplier for all bucket(sum)
    3)% of supplier for each bucket.(each bucket supp cnt *100/total supp cnt)
    3)total spend for each bucket
    4)total spend for all combination of bucket
    5)% of spend for each bucket than total bucket(each bucket supp spend *100/total supp spend)
    6)how many no of suppliers make 80% of total spend(respect to all bucket)I'm not certain I understand what any of the outputs are, but I'm especially unsure of 6) and 7).
    Do you want the smallest possible number of suppliers, such that their spend totals account for at least 80% of all spend total?
    Do you want the largest possible number of suppliers, such that their sepnd total just barely exceeds 80% of the overall total?
    Do you want something else entirely?
    When you post the results you want from the given sample data, explain this part very carefully.
    7)how many no of suppliers make 20% of total spend(respect to all bucket)
    8)top 3 suppliers make how much % of spend(respect to all bucket)I suspect you'll need to use aggregate functions to get the total by suppliers, and then use analytic fucntions to answer questions such as "Is the running total greater than 80% yet?". I'm sure this will be clearer after you post the results you want.

  • Cummulative total for quantity in goods issue row

    Dear all,
    Please advise on how it is possible to get the cummulative total of quantity in a udf in the goods issue row. Which query will work in the formatted search in the
    Kind Regards,
    Monil

    Dear Rahul,
    I have created another udf in the row which should contain the cummulative total of the quantity entered for the same item in the rows above.
    Regards,
    Monil.

  • Query for calculating financialyear

    help me to write a query  which will check if the record createdon
    is within  the current financialyear  i.e. June 2014- July 2015
    RecordCreatedon
    logic
    2014-10-28
    yes
    2014- 12-15
    Yes
    2012- 01-19
    No
    Note  : query for calculating financialyear should be hardcoded .

    It looks like your sample data range is wrong "June 2014- July 2015"
    To get an idea, I consider June 2014 - May 2015 as financial year, try the below:
    create Table test_Table (RecordCreatedon date)
    Insert into test_table values('2014-10-28'),('2014- 12-15'),('2014- 06-01'),('2014- 05-30')
    ,('2015- 02-28'),('2015- 05-30'),('2015- 06-01')
    Select *,
    case when year(Dateadd(month,-5,RecordCreatedon) )=YEAR(getdate()) Then 'yes' else 'no' end Logic
    From test_Table
    Drop table test_Table

  • Writing an sql script to query a calculation view  and an attribute view inside a calculation view

    Hi,
    I was trying to query a calculation view with sql , and as one of the input parameters i was trying to give a query over an attribute view
    So my sql will look like this
    SELECT * FROM "MyApp.calculation_views::GET_CHECKLIST_FOR_ACCOUNT"('PLACEHOLDER' = ('$$ACCOUNT_ID$$', '1','$$CHECKLIST_ID$$',' SELECT CHECKLIST_ID FROM "MyApp"."CHECKLIST_PRODUCTS" WHERE PRODUCT_ID = 5'));
    So as an input to $$CHECKLIST_ID$$   i wanted to give an id selected from checklist products table where products id is passed as an input
    but this is not working, i am getting syntax error at the $$CHECKLIST_ID$$ there i can only pass values like  $$CHECKLIST_ID$$, '1'
    Please help me to figure out which  is the correct syntax  i tried putting the sql statement to get the checklist_id in '' but it too didnot work

    I'm not sure you'll be able to do a SELECT subquery directly in the placeholder definition, but you can create another calc view (scripted) as a wrapper to your original calc view and use a scalar variable to pass the parameter over.
    Try this as the base code for your second calc view:
    var_id VARCHAR(10);
    BEGIN
         SELECT CHECKLIST_ID INTO :var_id FROM "MyApp"."CHECKLIST_PRODUCTS" WHERE PRODUCT_ID = 5;
         var_out = SELECT * FROM "MyApp.calculation_views::GET_CHECKLIST_FOR_ACCOUNT"
              (PLACEHOLDER."$$ACOUNT_ID" => 1, PLACEHOLDER."$$CHECKLIST_ID$$" => :var_id);
    END
    You could even create input parameters in the second Calc View for the Account Id & Product Id (which are currently hard coded in your code below).
    Best,
    Henrique.
    PS: avoid using SELECT * for the var_out in the scripted calc view. It's better, from a code maintenance perspective, to explicitly define the columns you're outputting.

  • Query to get PO total amount

    Hi,
    I want to do a query to get PO total value(sum of line item value), how to do that?
    In EKPO, it will show PO+Line item value, but the user requirement is to see PO total value under 5000 local currency.
    Please help, thanks.

    I will try again. For example, I have a table (Payments) that has 5 records. The 5 Payments table records has $24.45 entered all for the same person, Billy Bob that totals $122.25. I have a table (Members) that Billy Bob is one of 10 records. The query:QryTotalAmtDueBy
    returns 1 result (record) and it is only for Billy Bob for $122.25 because he is the only one entered in the Payments table. Total Amount Due: Sum([PaymentAmount]-[PPUnionDuesAmountNoDeduct])
    When I enter into the control source for text box:
    TextBoxTotalAmountDueToDateTab5 the expression: =DLookUp("[Total Amount Due]","[QryTotalAmtDueBy]","[MemberID]=" & [Forms]![Branch 142 Membership]![MemberID]) on the form: Branch 142 Membership. I get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the
    TextBoxTotalAmountDueToDateTab5.
    You suggested I try =DLookUp("Total Amount Due","QryTotalAmtDueBy"). I get #Error when I entered it in the text box:
    TextBoxTotalAmountDueToDateTab5. I modified what you gave me and entered: =DLookUp("[Total Amount Due]","[QryIndivTotalAmtDueBy]"). I still get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the Members table.
    I don’t care if I use a control source that references the
    Total Amount Due from the query QryTotalAmtDueBy or if I use a control source expression that is the sum
    of the PaymentAmounts minus the sum of the PPUnionDuesAmountNoDeduct for each record in the Members table. I've tried:
    =IIf(IsNull([MemberID]),0,DSum("[PPUnionDuesAmountNoDeduct]-[PaymentAmount]","Payments","[MemberID]=" & [MemberID])). I get nothing for
    any record in the Members table.

  • DLookUp Referencing a Query To Get a Total Amount Owed

    I have a form named: Branch 142 Membership that has a text box named: TextBoxTotalAmountDueToDate. The control source is: =DLookUp("[Total Amount Due]","[QryTotalAmtDueBy]","[MemberID]=" & [Forms]![Branch 142 Membership]![MemberID])
    I'm getting the sum total for all of the records in my database that is the sum for just one member. There's one payment record in the Payments table. Of course when I open the query I get the total for the one payment record.
    I want to get the Sum([PPUnionDuesAmountNoDeduct]-[PaymentAmount]) for each record in the object: TextBoxTotalAmountDueToDate.  If the amount is zero I want the text box to display zero. When I entered =Sum([PPUnionDuesAmountNoDeduct]-[PaymentAmount])
    I got an error in text box.
    Thanks for the help.

    I will try again. For example, I have a table (Payments) that has 5 records. The 5 Payments table records has $24.45 entered all for the same person, Billy Bob that totals $122.25. I have a table (Members) that Billy Bob is one of 10 records. The query:QryTotalAmtDueBy
    returns 1 result (record) and it is only for Billy Bob for $122.25 because he is the only one entered in the Payments table. Total Amount Due: Sum([PaymentAmount]-[PPUnionDuesAmountNoDeduct])
    When I enter into the control source for text box:
    TextBoxTotalAmountDueToDateTab5 the expression: =DLookUp("[Total Amount Due]","[QryTotalAmtDueBy]","[MemberID]=" & [Forms]![Branch 142 Membership]![MemberID]) on the form: Branch 142 Membership. I get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the
    TextBoxTotalAmountDueToDateTab5.
    You suggested I try =DLookUp("Total Amount Due","QryTotalAmtDueBy"). I get #Error when I entered it in the text box:
    TextBoxTotalAmountDueToDateTab5. I modified what you gave me and entered: =DLookUp("[Total Amount Due]","[QryIndivTotalAmtDueBy]"). I still get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the Members table.
    I don’t care if I use a control source that references the
    Total Amount Due from the query QryTotalAmtDueBy or if I use a control source expression that is the sum
    of the PaymentAmounts minus the sum of the PPUnionDuesAmountNoDeduct for each record in the Members table. I've tried:
    =IIf(IsNull([MemberID]),0,DSum("[PPUnionDuesAmountNoDeduct]-[PaymentAmount]","Payments","[MemberID]=" & [MemberID])). I get nothing for
    any record in the Members table.

  • Query Help-2

    Query Help:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
    It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
    The above was my previous posting, which was not clear..so Iam restating my problem as follows....
    I have the following tables
    Customer(custID, Name, Address)
    Order(custID, OrderID, orderDate)
    CreditCard(custID, creditCard#, creditCardType)
    Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
    Order:
    100,A001,11/22/03
    100,A002,11/24/03
    100,A003,12/02/03
    CreditCard:
    100,42323232..., VISA
    100,5234234...., MASTER
    Now how can I get
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    data in minimum no. of records....
    I think I have made my query clear..
    now please help me guys...
    thanks so much for your help.

    You are right.
    But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
    Can you please help me with the query
    if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
    With the following fields in my query result,
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    from Customer, Order, CreditCard tables
    Thanks so much for your htlp

  • SQL query not calculating

    SQL query not calculating
    gross_amount is giving the value of extended_amount and the gross_price_rc is giving the value of unit_selling_price
    select customer_trx_line_id,
    ( extended_amount / 1- (decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) GROSS_AMOUNT,
    ( unit_selling_price /1-(decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) gross_price_rc
    from ra_customer_trx_lines_all
    where attribute6 is not null or attribute7 is not null or attribute8 is not null or attribute9 is not null
    whats the isuue here??
    Thanks

    decode(attribute7,null,0)Looking at it again, this always returns 0 or NULL, so it not really surprising
    DECODE
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions040.htm#i1017437
    CASE
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions004.htm#i1033392

  • SQL Query Help - Is this possible or impossible????

    Hi guys,
    I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
    For example,
    I have 2 tables
    The first table is:
    1) COMPANY create table company (manufacturer varchar2(25),
                                                          date_established date,
                                                          location varchar2(25) );My sample test date is:
    insert into company values ('Ford', 1902, 'USA');
    insert into company values ('BMW', 1910, 'Germany');
    insert into company values ('Tata', 1922, 'India');The second table is:
    2) MODELS create table models (manufacturer varchar(25),
                                                 model varchar2(25),
                                                 price number(10),
                                                 year date,
                                                 current_production_status varchar2(1) ) ;My sample test data is:
    insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
    insert into models values ('Ford', 'Galaxy', 12000,   2008, 0);
    insert into models values ('Ford', 'Escort', 10000, 1992, 1);
    insert into models values ('BMW', '318', 17500, 2010, 0);
    insert into models values ('BMW', '535d', 32000,   2006, 0);
    insert into models values ('BMW', 'Z4', 10000, 1992, 0);
    insert into models values ('Tata', 'Safari', 4000, 1999, 0);
    insert into models values ('Tata', 'Sumo', 5500,   1996, 1);
    insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer IN ('Ford', 'BMW', 'Tata')
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCWhat I want the query to output is this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               Sumo               5500               1998          1If current_production_status is 1 it means this particular model has been discontinued
    If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
    The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
    So the query should output the one row where current_production_status is 1 for each manufacturer.
    If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
    My query as it is above will output all the records where current status is 1 or 0 like this
    com.manufacturer        com.date_established          com.location          mod.model          mod.price          mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    Tata               1922                    India               Sumo               5500               1998          1
    Ford               1902                    USA               -               -               -          0                    
    Ford               1902                    USA               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               -               -               -          0
    Tata               1922                    India               -               -               -          0However this is not what I want.
    Any ideas how I can achieve the result I need?
    Thanks!
    P.S. Database version is '10.2.0.1.0'

    Hi Vishnu,
    Karthiks query helped...
    But this is the problem I am facing...
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer = 'Ford'
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCThe value of:
    and com.manufacturer = 'Ford'will be dependent on front end user input....
    When I run the query above I get all the rows where current_production_status is either 1 or 0.
    I only require the rows where current_production_status is 1.
    So if I amend it to look like this:
         and mod.current_production_status = 1This works....
    BUT if a user now passes in more than one manufacturer EG:
    and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
    So like this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
    Thanks you so much!
    This is really driving me insane :-(

  • Query regarding calculation in OBIEE

    I have below columns in the report
    Cust ID Customer Segment Total sales %of sales
    121 A 300
    123 B 400
    124 C 600
    126 D 500
    %of sales to be calculated as total sales/sum of sales for a,b,C category
    Hoe to calculate it?
    Note in denominator I want summ of only A,b,c category (D not included)
    Thanks!

    Hi
    In report column formula use the filter option you can get the results according to your requirement.
    Thanks
    Don

  • Calculations on Total column' fields(bps layout: dynamic calmonth)

    hi friends,
    in bps, output layout, based on dynamic calmonth i showing number of months.  I want to system to calulate total(all calmonths) sum for a particular field.
    Lead column    data columns
    Expenses      apr2009  may 2009 june 2009.....mar2010   Total
      Office             20         10        20                                       100
    Usually for caculating total in layout builder 2nd screen, we chose tickmark(total) and then write c(1): c(1)   like that or simply c(1) which calculates all calmonth values.
    My situation is like this, user only enter number of year(s), in terms of range. I populate calmonth field using user-exit based on  year range. Next using calmonth field in layout builder as dynamic field. Now user wants  TOTAL of individual years along with calmonths.  How can i put this condition in layout builder?
    eg:
                       apr2009 may 2009......mar2010  Total(09-10)  apr2010 may 2010  ...mar2011  Total(10-11).apr2011 ..Total(11-12).
    Expenses   10           20   30..............
    Next question, Can i do arthemetic calculation on total fields?
    eg:
    Lead column     apr09 may09 ....mar10 total
    A                         10      20                           100
    B                          20     30                             200
    c                           10    5                              ????(this value i want to calulate by above totals eg:   (200/100)* 85.
    Can it possible to get that?
    thanks,
    kumar

    It is not possible to hide or change the column width during design time if the layout is ALV.
    However if the layout is used in WIB (web interface builder), I believe the column widths can be modified at run time. This would need additional coding.
    Regards

  • Need a query help

    hii
    i need a query help
    i have two tables
    the 1st table will look like this
    associate id weekid no.of. hours
    4000 810 40
    4000 820 30
    4000 830 60
    4000 840 70
    2nd table will look like this
    associate id weekid no.of.hours
    4000 810 40
    4000 820 70
    4000 830 130
    4000 840 200
    so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
    the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
    for example
    consider week id 830 and 840
    in second table 830=130
    840=200
    when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
    1 ---->>>> 840 - 830
    =200 - 130
    =70
    in first table 840 has 70 hrs
    like this it shud check with all records and it shud return only the records which are not equal
    regards
    srikanth

    This..?
    sql>select * from t1;
    A_ID W_ID HRS
    4000  810  40 
    4000  820  30 
    4000  830  60 
    4000  840  70 
    4000  850  80 
    sql>select * from t2;
    A_ID W_ID HRS 
    4000  810  40 
    4000  820  70 
    4000  830  130 
    4000  840  200 
    4000  850  260 
    sql>
    select a_id,w_id,hrs,sum_hrs
    from(
    select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
           t2.hrs - nvl(lag(t2.hrs)  over(order by t1.w_id),0) diff
    from t1,t2
    where t1.w_id = t2.w_id)
    where diff != hrs;
    A_ID W_ID HRS SUM_HRS 
    4000  850  80  260                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • MDX Query to Calculated member

    Hi All,
    I have a MDX query which works fine, when converting the query to Calculated member, I get the same result for all the rows of a dimension.
    select {[Measures].[Contents]} on 0,
    ([Dim Products].[Product Alias].[Product Alias].members,
    (filter ([Dim Products].[Product ID].members,
    instr(left([Dim Productss].[Product ID].currentmember.member_Key,3),'112')>0))) on 1
    from
    <<CubeName>>
    Calculated Member:
    SUM(filter ([Dim Products].[Product ID].members,
    instr(left([Dim Products].[Product ID].currentmember.member_Key,3),'112')>0),[Measures].[Contents])
    When I drag the dimension product, the calculated member showing the same result for all the products. Can anyone let me know the syntax error here.

    Hi SQL GUN,
    For me it works :
    WITH MEMBER [Last3MonthsInternetSales] AS 
    AGGREGATE
    LastPeriods(-3, ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[Month].&[2005]&[12])), 
    [Measures].[Internet Sales Amount]
    SET MySet AS
    {[Date].[Calendar].[Month].&[2005]&[09],
    [Date].[Calendar].[Month].&[2005]&[10],
    [Date].[Calendar].[Month].&[2005]&[11],
    [Date].[Calendar].[Month].&[2005]&[12],
    [Date].[Calendar].[Month].&[2006]&[01],
    [Date].[Calendar].[Month].&[2006]&[02]}
    SELECT
    [Measures].[Internet Sales Amount],
    [Last3MonthsInternetSales]
    } ON COLUMNS,
    MySet
    } ON ROWS
    FROM [Adventure Works]
    Are u sure your query is correct. I think you might have a [Fiscal Month Num of Year] too much in your (). I'm not sure, but are u dragging the correct level of hierarchy ? Also in the part ON ROWS you seem to take a lot of levels with you.
    Why for example take .allmembers when you only want the actual last 3 of your currentmember?
    Can u check again?

  • [10g/8i] Need help calculating a hierarchical total

    Hi all...
    I am trying to determine the total quantity of each unique part number in a bill of materials (big list of parts that go into a final product). The total needs to take into account the quantity of the parent parts--what I mean by this is, if you have final product 'A' that takes 1 x part 'B' and 2 x part 'C', and part 'C' takes 1 x part 'B' and 3 x part 'D' then the totals of all unique parts in product 'A' would be: 3 x B, 2 x C, 6 x D.
    It would be nice if this query ran under 8i, but if it's much more complex than the equivalent query for 10g, don't worry about making it work for 8i.
    Here is some sample data:
    CREATE TABLE     BOM
    (     part_nbr     CHAR(25)
    ,     bill_seq     VARCHAR2(140)
    ,     bill_level     NUMBER
    ,     parent_part     CHAR(25)
    ,     line_nbr     NUMBER(5)
    ,     child_part     CHAR(25)
    ,     qty_per          NUMBER(9,5)
    INSERT INTO BOM VALUES ('12345-1','   10019970303',1,'12345-1',100,'12345-76',1);
    INSERT INTO BOM VALUES ('12345-1','   20019970303',1,'12345-1',200,'12345-272',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303',1,'12345-1',300,'12345-267',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303   10019830901',2,'12345-267',100,'12345-268',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303   10019830901   10019830901',3,'12345-268',100,'12345-268-1',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303   20019830901',2,'12345-267',200,'12345-269',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303   30019830901',2,'12345-267',300,'12345-270',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303   40019830901',2,'12345-267',400,'HARDWARE-4',1);
    INSERT INTO BOM VALUES ('12345-1','   30019970303   50019830901',2,'12345-267',500,'HARDWARE-5',1);
    INSERT INTO BOM VALUES ('12345-1','   40019970303',1,'12345-1',400,'HARDWARE-6',2);
    INSERT INTO BOM VALUES ('12345-1','   50019990824',1,'12345-1',500,'A12345-475',1);
    INSERT INTO BOM VALUES ('12345-1','   60019970303',1,'12345-1',600,'HARDWARE-7',1);
    INSERT INTO BOM VALUES ('12345-1','   70019990824',1,'12345-1',700,'A12345-476',1);
    INSERT INTO BOM VALUES ('12345-1','   70019990824   10019990824',2,'A12345-476',100,'A12345-476-1',1);
    INSERT INTO BOM VALUES ('12345-1','   80019970303',1,'12345-1',800,'12345-222',1);
    INSERT INTO BOM VALUES ('12345-1','   90019970303',1,'12345-1',900,'12345-157',1);
    INSERT INTO BOM VALUES ('12345-1','   90019970303   10119980922',2,'12345-157',101,'RAW-2',6.2);
    INSERT INTO BOM VALUES ('12345-1','  100019990215',1,'12345-1',1000,'A12345-494',2);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216',2,'A12345-494',100,'A12345-486',1);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216   10019000101',3,'A12345-486',100,'12345-158',1);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216   10019000101   10119960118',4,'12345-158',101,'RAW-3',6.75);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216   10120000317',3,'A12345-486',101,'RAW-3',6.75);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   20019970303',2,'A12345-494',200,'12345-155',1);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   30019970303',2,'A12345-494',300,'12345-266',1);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   40019990215',2,'A12345-494',400,'A12345-493',1);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   50019970303',2,'A12345-494',500,'HARDWARE-8',1);
    INSERT INTO BOM VALUES ('12345-1','  100019990215   60019970303',2,'A12345-494',600,'HARDWARE-9',1);
    INSERT INTO BOM VALUES ('12345-1','  110019970303',1,'12345-1',1100,'HARDWARE-10',1);
    INSERT INTO BOM VALUES ('12345-1','  120019970303',1,'12345-1',1200,'HARDWARE-9',1);
    INSERT INTO BOM VALUES ('12345-1','  130019970303',1,'12345-1',1300,'HARDWARE-11',2);
    INSERT INTO BOM VALUES ('12345-1','  140020000228',1,'12345-1',1400,'HARDWARE-12',1);
    INSERT INTO BOM VALUES ('12345-1','  150020000228',1,'12345-1',1500,'HARDWARE-13',2);
    INSERT INTO BOM VALUES ('12345-1','  160020000228',1,'12345-1',1600,'HARDWARE-14',2);
    INSERT INTO BOM VALUES ('12345-1','  170020000228',1,'12345-1',1700,'12345-250',8);
    INSERT INTO BOM VALUES ('12345-1','  180020000228',1,'12345-1',1800,'FLUID1',0.00001);
    INSERT INTO BOM VALUES ('ABC-123','   10019000101',1,'ABC-123',100,'ABC-123-1',1);
    INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101',2,'ABC-123-1',100,'AYZ-1',2);
    INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101   10019000101',3,'AYZ-1',100,'AYZ-2',1);
    INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101   10019000101   10019000101',4,'AYZ-2',100,'RAW-1',1);
    INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101   20019000101',3,'AYZ-1',200,'HARDWARE-1',10);
    INSERT INTO BOM VALUES ('ABC-123','   20020001110',1,'ABC-123',200,'HARDWARE-2',15);
    INSERT INTO BOM VALUES ('ABC-123','   30020001121',1,'ABC-123',300,'HARDWARE-1',26);
    INSERT INTO BOM VALUES ('ABC-123','   40019000101',1,'ABC-123',400,'AYZ-25',1);
    INSERT INTO BOM VALUES ('ABC-123','   50020001121',1,'ABC-123',500,'HARDWARE-3',5);Here are the results I expect (I don't care about the order, this is just the order I hand-calculated the results in):
    PART_NBR    CHILD_PART  TOTAL_QTY  
    ABC-123     ABC-123-1   1          
    ABC-123     HARDWARE-1  46         
    ABC-123     HARDWARE-2  15         
    ABC-123     HARDWARE-3  5          
    ABC-123     RAW-1       1          
    ABC-123     AYZ-1       2          
    ABC-123     AYZ-2       2          
    ABC-123     AYZ-25      1          
    12345-1     12345-155   1          
    12345-1     12345-157   1          
    12345-1     12345-158   2          
    12345-1     12345-222   1          
    12345-1     12345-250   8          
    12345-1     12345-266   1          
    12345-1     12345-267   1          
    12345-1     12345-268   1          
    12345-1     12345-268-1 1          
    12345-1     12345-269   1          
    12345-1     12345-270   1          
    12345-1     12345-272   1          
    12345-1     12345-76    1          
    12345-1     A12345-475  1          
    12345-1     A12345-476  1          
    12345-1     A12345-476-11          
    12345-1     A12345-486  2          
    12345-1     A12345-493  1          
    12345-1     A12345-494  2          
    12345-1     FLUID1      0.00001    
    12345-1     HARDWARE-10 1          
    12345-1     HARDWARE-11 2          
    12345-1     HARDWARE-12 1          
    12345-1     HARDWARE-13 2          
    12345-1     HARDWARE-14 2          
    12345-1     HARDWARE-4  1          
    12345-1     HARDWARE-5  1          
    12345-1     HARDWARE-6  2          
    12345-1     HARDWARE-7  1          
    12345-1     HARDWARE-8  1          
    12345-1     HARDWARE-9  2          
    12345-1     RAW-2       6.2        
    12345-1     RAW-3       27          Clearly this query:
    SELECT     part_nbr
    ,     child_part
    ,     SUM(qty_per)
    FROM     BOM
    GROUP BY     part_nbr
    ,          child_part
    ORDER BY     part_nbr
    ,          child_part
    ;will not give the desired results, as it doesn't take into account the quantity required of each child's parent, but I can't figure out how to do that.
    The sample data I have provided represents data from a table or materialized view that is, roughly, the result of a hierarchical query of data in another table or three. If it's simpler to work off the tables on which this table is based, let me know, and I can put together some sample data from those tables.

    Hi,
    user11033437 wrote:
    Hi all...
    I am trying to determine the total quantity of each unique part number in a bill of materials (big list of parts that go into a final product). The total needs to take into account the quantity of the parent parts--what I mean by this is, if you have final product 'A' that takes 1 x part 'B' and 2 x part 'C', and part 'C' takes 1 x part 'B' and 3 x part 'D' then the totals of all unique parts in product 'A' would be: 3 x B, 2 x C, 6 x D.That's a very good explanation in general terms. No doubt, for you, applying that to the specific data is trivial, but most of us aren't as familiar with your application as you are. It would help a lot if you posted a similar explanation using specific ids from the sample data. For example, why do the desired results include:
    PART_NBR    CHILD_PART  TOTAL_QTY  
    ABC-123     HARDWARE-1  46     If someone explores the data enough, they might guess that the number 46 is the sum of 26 and 20=2*10, but it would sure save a lot of time if you, to whom this is second nature, could explain it.
    It would be nice if this query ran under 8i, but if it's much more complex than the equivalent query for 10g, don't worry about making it work for 8i. Sorry, I don't know any simple way to do this in Oracle 8.1. The SYS_CONNECT_BY_PATH function, introduced in Oracle 9, is essential to the solution below.
    Here is some sample data:
    CREATE TABLE     BOM
    INSERT INTO BOM VALUES ('ABC-123','   50020001121',1,'ABC-123',500,'HARDWARE-3',5);
    Good job.
    It looks like only about half of the columns have anything to do with this problem. Here's another place where sharing your knowlege ot he application could really help people. Don't post things that are irrelvant to the problem you're asking. If there's a sincere doubt, then say somthing like "I need part_nbr, bill_seq and bill_level in the output for my real problem. I don't think they have anything to do with getting the total qty, but I'm posting them just in case."
    Here are the results I expect (I don't care about the order, this is just the order I hand-calculated the results in):
    PART_NBR    CHILD_PART  TOTAL_QTY  
    ABC-123     ABC-123-1   1          
    ABC-123     HARDWARE-1  46    
    12345-1     RAW-3       27          Clearly this query:
    SELECT     part_nbr
    ,     child_part
    ,     SUM(qty_per)
    FROM     BOM
    GROUP BY     part_nbr
    ,          child_part
    ORDER BY     part_nbr
    ,          child_part
    ;will not give the desired results, as it doesn't take into account the quantity required of each child's parent, but I can't figure out how to do that.Thanks for posting the query. Even though it doesn;t work, it helped me understand what you wanted, and saved me some time.
    The sample data I have provided represents data from a table or materialized view that is, roughly, the result of a hierarchical query of data in another table or three. If it's simpler to work off the tables on which this table is based, let me know, and I can put together some sample data from those tables.I don't know if it would be any simpler. It might be more efficient, but I don't know how much that matters to you. Try the solution below. If it takes, say, 60 seconds, is it worthwhile trying to see if we can get it to run in 15?
    This seems to get the right results:
    SELECT     part_nbr
    ,     child_part
    ,     SUM (eval_number ('1' || SYS_CONNECT_BY_PATH (qty_per, '*')))     AS total_qty
    FROM     bom
    START WITH     parent_part     = part_nbr
    CONNECT BY     parent_part     = PRIOR child_part
    GROUP BY  part_nbr
    ,       child_part
    ORDER BY  part_nbr
    ,       child_part
    ;Do some experiments, on variations of this query, if you don't understand what SYS_CONNECT_BY_PATH is doing. You'll see that it's returning a string, such as '*2*1*1*6.75' that reflects the quantities needed at each level of the process. To actually do the multiplication, and get a number, I used this function:
    CREATE OR REPLACE FUNCTION     eval_number
    (     in_txt     IN     VARCHAR2
    ,     err_val     IN     NUMBER     DEFAULT     NULL
    RETURN     NUMBER
    IS
    --          **   e v a l _ n u m b e r   **
    --          eval_number attempts to evaluate in_txt as a NUMBER,
    --          returning that value.  If in_txt can not be interpreted,
    --          then err_val is returned.
         result_txt     VARCHAR2 (100);
         return_val     NUMBER;
    BEGIN
         EXECUTE IMMEDIATE     'SELECT '
                   ||     in_txt
                   ||     ' FROM dual'
                   INTO     return_val;
    --     dbms_output.put_line (result_val || ' = result_txt in eval_number');
         RETURN     return_val;
    EXCEPTION
         WHEN OTHERS
         THEN
    --          dbms_output.put_line (SQLERRM || ' = error in eval_number');
              RETURN     err_val;
    END     eval_number
    SHOW ERRORSI hate using "WHEN OTHERS" like this. Perhaps someone can suggest a reasonable set of specific errors that could be caught in the EXCEPTION section.

Maybe you are looking for

  • Automatic Creation and Confirmation of Warehouse Task in EWM 5.1

    Hello, We want an automatic creation and confirmation of the warehouse task in EWM 5.1 on the based of a delivery type and warehouse number. The scenario goes in this way... As soon as the inbound delivery is created/replicated in EWM, the creation a

  • SOM Error while using Dynamic Tables

    Hi Gurus,     I have created a Adobe form with Dynamic tables and integrated in Webdynpro ABAP. When I test the form, while opening the form the following error occurs .. " The SOM Expression '$record.BP_DETAILS' for the dataRef specified on field 'B

  • Why can't pp cs6 open my  mpg4 files from my secuity cam footage?

    Just got Swann system and it exports mpg4. Can't find way to import to PPro cs6.

  • I found a globalmenu for Mate

    Well I was in search of a globalmenu for Mate DE. There was no globalmenu for mate until the time I found this link :- http://forums.linuxmint.com/viewtopic.p - 7&t=114613 jasmineaura in above link has already forked compiz as compiz-mate & gnome2-gl

  • RMI callback client stub

    I am new to RMI. We have a server component that runs within its own JVM.It needs to callback on client applets/consoles etc. Ordinarily,the client would implement an interface, and distribute the interface and remoting stub to the server ,for the se