Trying to get ending effective date for groups of rows

Hi Everyone,
I've searched the forums, but I can't find a post that presents a problem quite like this.
I have some data that looks like this:
        ID_NUM     EFFECTIVE ALLOC_PERCENT   ACCT
       101 01-JUL-11            21   A1
       101 01-JUL-11            72   A2
       101 01-JUL-11             7   A3
       101 01-JUL-12            20   B1
       101 01-JUL-12            80   B2
       101 01-JAN-13            20   A1
       101 01-JAN-13            20   A2
       101 01-JAN-13            50   A3
       101 01-JAN-13            10   B1
       101 01-JUN-13            50   A1
       101 01-JUN-13            50   A2(note - I manually inserted blank lines for clarity)
Here's the logic: The rows represent a percentage allocation to the account number for the specified id number, for that effective date. A newer effective date supercedes previous ones, and if any row in the conceptual group is superceded, then they all are.
I'm trying to find out the date when each group's effective period ended, and include that in the result set so that I can subsequently calculate the number of days a given row was effective; something like this;
  ID_NUM     EFFECTIVE END_DATE   ALLOC_PERCENT ACCT
       101 01-JUL-11 01-JUL-12             21 A1
       101 01-JUL-11 01-JUL-12             72 A2
       101 01-JUL-11 01-JUL-12              7 A3
       101 01-JUL-12 01-JAN-13             20 B1
       101 01-JUL-12 01-JAN-13             80 B2
       101 01-JAN-13 01-JUN-13             20 A1
       101 01-JAN-13 01-JUN-13             20 A2
       101 01-JAN-13 01-JUN-13             50 A3
       101 01-JAN-13 01-JUN-13             10 B1
       101 01-JUN-13 <null>                50 A1
       101 01-JUN-13 <null>                50 A2The END_DATE of the group is the EFFECTIVE_DATE of the following group (ordered by ID_NUM, EFFECTIVE_DATE).
The last two rows' END_DATE is null because there is no group of rows with a later effective date - in my process, I'll NVL that to sysdate so that my days calculations will be valid.
I tried some analytic queries with LEAD, but I couldn't figure out how to make it get the next group's effective date. I could get the next row's effective date, but not the next group's. I couldn't specify how many lead rows to look ahead, because there is not a consistent number of rows in each group.
How do I populate the END_Date column?
Here's the code to create the above.
create table t
(id_num number,
effective_date date,
alloc_percent number,
acct_code varchar2(4)
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',21.0,'A1');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',72.0,'A2');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',7.0,'A3');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2012',20.0,'B1');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2012',80.0,'B2');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',20.0,'A1');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',20.0,'A2');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',50.0,'A3');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',10.0,'B1');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jun-2013',50.0,'A1');
insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jun-2013',50.0,'A2');
commit;
select * from t;Oracle version information:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE     11.2.0.3.0     Production"
TNS for Solaris: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Thank you very much

select  id_num,
        effective_date,
        first_value(effective_date)
          over(
               partition by id_num
               order by effective_date
               range between 1 following and unbounded following
              ) end_date,
        alloc_percent,
        acct_code
  from  t
  order by id_num,
           effective_date
    ID_NUM EFFECTIVE END_DATE  ALLOC_PERCENT ACCT
       101 01-JUL-11 01-JUL-12            21 A1
       101 01-JUL-11 01-JUL-12            72 A2
       101 01-JUL-11 01-JUL-12             7 A3
       101 01-JUL-12 01-JAN-13            20 B1
       101 01-JUL-12 01-JAN-13            80 B2
       101 01-JAN-13 01-JUN-13            20 A1
       101 01-JAN-13 01-JUN-13            10 B1
       101 01-JAN-13 01-JUN-13            20 A2
       101 01-JAN-13 01-JUN-13            50 A3
       101 01-JUN-13                      50 A1
       101 01-JUN-13                      50 A2
11 rows selected.
SQL> SY.

Similar Messages

  • Effective date for a Formulation row

    Hi,
    our customer manage in JDE the effective date for each formulation row.
    I.e.: In a particular formulation a particular salt is valid from 1-gen-2013 to 1-feb-2013.
    In the same formulation another salt is valid from 2-feb-2013 to 1-mar-2013.
    Is there a way to handle this also in PLM4P? Are there other customer that have the same formula management?
    I hope my question is clear.
    Thanks and regards.
    Stefano.

    Hi Stefano,
    have you thought about using the Alternate Input Items to achieve this scenario? you can put description to clarify that the particular salt only available in certain amount of time. Hope this will be helpful.
    Thanks,
    Jessie

  • Effective Date for Yearly Increment

    We are having different effective dates for Salary and Hourly employees for whom I have created two Guideline groups but under the same Comp Plan and Comp Review Item. I am getting the desired increase Dollar amount in Annual figure for Salary and hourly figure for Hourly. But, the effective date is also taking same as per the Comp Review Item. When I tried to add one more comp review item for Hourly, I am not able to do with the same combination of Plan and Review.
    So, how can I get the respective effective date as we have only one place to define the same? Do I have to create one more Comp Plan for the Hourly employees?
    Thanks

    I was thinking your issue was with applying the appropriate guidelines.. If it is only the effective date, you can implement the BAdI HRECM00_EFFDATE & pass back the new effdt in the method GET_DEFAULT_EFF_DATE.
    ~Suresh

  • I am using Adobe Pro 11 and on opening a pdf I am getting error 'Insufficient Data for an Image'. Please help and provide a workaround if the solution not there.

    Hi all,
    I am using Adobe Pro 11 and on opening a pdf I am getting error 'Insufficient Data for an Image'. Please help and provide a workaround if the solution not there.
    I have already set the preferences to for page view to low zoom settings, and page fit view settings, but it never opens the pdf. Please check and provide a solution asap.
    Thanks in advance!

    Most of the documents have sensitive info on them.  I will have to do some looking for some that i can share, but will get something to upload (dropbox) as soon as I can.
    Thanks for you help.

  • How to get the histoical data for newly added field in the cube?

    Hi Experts,
    I have small doubt on remodeling the infocube.
    After adding the characteristic or keyfigure  to a cube by using remodeling concept, how can I get the historical data for that particular field.
    I have searched in SDN also but I didn't get proper information.
    Please excuse me if I posted repeated question.
    helpful answer will be awarded with poitns.
    Thanks & regards,
    Venkat.

    hi
    depending on your customer need you could use the remodelling functionnality but sometimes you have no way to retrieve what you want so another option you should consider is the following:
    Advantages
    that will cost less effort and guarantee the result.
    Drawbacks
    data is redondant for a while
    space (depending on the volume of historical data)
    So here are the steps :
    step 1Adjust your extraction process according to the fields you need to add to populate the cube.
    step 2 Then create a dso next or even a cube, feed the dso with a full load with the enhanced extractor you adjusted with the new fields in step 1 only once in fact this should be one shot.
    step 3 Copy the query to the previous built  multi-provider on top of the new historical data from dso and the running live delta cube. Adjust the queries if necessary.
    optionnal Then if you want to get rid of the dso or new cube for historical data you could empty the actual one push the data from the new data provider and that's all.
    bye
    Boujema

  • Get Password Expiration Date of Group members in Active Directory

    hi,
    How can I get password Expiration date of Group members in Active Directory – please advise me
    Fasil CV

    Or DSQUERY Commands.
    dsget group "CN=Group1,DC=myinfralab,DC=com" -members | dsget user - -acctexpires
    Santhosh Sivarajan | Houston, TX | www.sivarajan.com
    ITIL,MCITP,MCTS,MCSE (W2K3/W2K/NT4),MCSA(W2K3/W2K/MSG),Network+,CCNA
    Windows Server 2012 Book - Migrating from 2008 to Windows Server 2012
    Blogs: Blogs
    Twitter: Twitter
    LinkedIn: LinkedIn
    Facebook: Facebook
    Microsoft Virtual Academy:
    Microsoft Virtual Academy
    This posting is provided AS IS with no warranties, and confers no rights.

  • Delivery grouping and the delivery date for group in SD

    Hi
    Using a userexit I am grouping certain materials together.  However the delivery date for group field is not picking up the expected date.
    Assume the following example:
    Material X            Delivery Date 20.12.2006
    Material Y           Delivery Date 27.12.2006
    If I group them together I expect the delivery date for the group to become 27.12.2006 however it is picking up 20.12.2006.
    If anyone has some thoughts regarding this they would be most appreciated.

    Yeah got ur point i was mapping the table configuaration for ur reference.
    This grouping is supposed to make sure that all materials are delievered at the same Date (VBEP-EDATU) and must use the last date in the delivery group.
    say materials  X -- DELIVERY DATE  20 12 2006
                         Y -- DELIVERY DATE  27 12 2006
    so the matnrs are avalaible in VBAP along with  for the VBELN and POSNR values now pick the delivery date for this material from VBEP   ,,
    Now once the itab is sorted by delivery group  and EDATU descending .
    so X and Y are present in for delivery group 001 say .
    X -- DELIVERY DATE  20 12 2006
    Y-- DELIVERY DATE  27 12 2006
    after sort by date it will be
    Y-- DELIVERY DATE  27 12 2006
    X -- DELIVERY DATE  20 12 2006
    which will pick up the latest date (or max date)
    Tis was what i meant to say.
    what is the incude you r using ?
    regards,
    vijay

  • Who to get Actual Shipment Date for the Sales Order

    Dear All,
         How to Get Actual Shipment Date for the given sales order.
    REgards
    sudheer

    Hai,
    If you want the actual shipment date of an order call the function module RV_ORDER_FLOW_INFORMATION and pass the order number as vbeln in the structure COMWA.select the values from the return table which corresponds to 'J' type which are delivery and get thedate.
    THis will give the actual delivery date (if created).
    Oher way is to look for vbeln in table LIPS using VGBEL = order number as the selection criteria.
    Cheers,
    Sandeep

  • Please help.   My Adobe InDesign document keeps crashing when I adjust the screen resolution to High in the View menu.  Desperately trying to get my magazines prepared for press today!  HELP!

    Please help.   My Adobe InDesign document keeps crashing when I adjust the screen resolution to High in the View menu.  Desperately trying to get my magazines prepared for press today!  HELP!
    My magazine last month is still working ok - but this month's version has just started crashing for some reason.

    We can't know. You have not provided any system info, not told us what version of ID you use nor provided any specifics about the document like images, color profiles, fonts, paragraph styles and what have you...
    Mylenium

  • Trying to get safari search history for past 3 weeks.  Way to change one week default setting?

    trying to get safari search history for past 3 weeks.  Way to change one week default setting?

    trying to get safari search history for past 3 weeks.  Way to change one week default setting?

  • How should i get the delta data for those new object's previous delta data?

    Hallo all,
    i have 2lis_11_vahdr and i am using a standard and loading delta! now i have appended some new fields in the datasource then in infosource then in ods and infocube..! now how should i get the delta data for those new object's previous delta data???
    Jimmy

    Hi,
    After appending new fields in the datasoure.It is not possible to delta load, u should have to load everything
    Thanks,
    Shreya

  • If there is no data for a specific row, please don't show the row at all.

    Hi,
    If there is no data for a specific row, please don't show the row at all.
    how can this be done??
    Thanks in advance.

    Not clear no data for row?
    Did you try with Pivot table? that should take care of it.
    Let us know updates

  • SQL command to get latest effective date

    Hi!
    How can i want to write a sql command to fetch records as such
    Vendor;    Item;     EffectiveDate;    UnitPrice;    Remarks
    Vend1;      ABC;    31/01/2012;        120;            Dont show
    Vend1;      ABC;    29/02/2012;        150;            Show
    Vend2;      ABC;    01/01/2012;        140;            Show
    Vend1;      XYZ;    15/01/2012;        100;            Show
    Please help me, so far I can only figuire out how to get the latest effective date by vendor and item but was not able to get UnitPrice
    SELECT  "VendPart"."Vendor", "VendPart"."Item", Max("VendPart"."EffectiveDate") AS MaxOfEffectiveDate
    FROM   "POS_LiveRpt"."dbo"."VendPart" "VendPart"
    GROUp BY "VendPart"."Vendor", "VendPart"."Item"
    Edited by: MichellePoh on Feb 23, 2012 9:58 AM

    hi Michelle,
    you can use a subquery in your command to bring back the UnitPrice that is applicable to the max date...see the code below for an idea.
    you'll have to change the "UnitPrice" field below to match yours.
    note that in the subquery the vendpart table has been aliased as vendpart2 for the subquery to work. also note that the code may not work in your database as Alan aluded to the fact that the syntax is specific to the database type...if you get any database errors please refer to your database manual or a forum for your database type that has a subquery. and of course there may be errors from my typing in the query as it's just being done inside this forum thread...but hopefully this will give you an idea how to do this.
    cheers,
    jamie
    SELECT 
    "VendPart"."Vendor",
    "VendPart"."Item",
    Max("VendPart"."EffectiveDate") AS MaxOfEffectiveDate,
    SELECT "VendPart2"."UnitPrice"
    FROM "POS_LiveRpt"."dbo"."VendPart" "VendPart2"
    WHERE "VendPart2"."EffectiveDate" = Max("VendPart"."EffectiveDate")
    AND  "VendPart2"."Vendor" =  "VendPart"."Vendor"
    AND "VendPart2"."Item" = "VendPart"."Item"
    ) AS UnitPrice
    FROM  
    "POS_LiveRpt"."dbo"."VendPart" "VendPart"
    GROUp BY
    "VendPart"."Vendor", "VendPart"."Item"

  • Can you get file creation dates for Nomad II .NVF fil

    Hi,
    I have an old Nomad II MG that has several voice recordings of my daughter over the last 4 years, but I don't know the dates they were recorded.
    Is there a way to get the actual date of the recording from the Nomad device? All I seem to end up with is the current date when I upload it into Windows.
    Thanks...
    lj

    Hi,
    Newbie to SharePoint, learn quite a lot from the links you provided.
    “I found out that the original dates are only available in SharePoint if the explorerview has been used”, this would make sense because the original creation time is generated
    by the file system in the local machine.
    However, when a file is uploaded to SharePoint library, it will be stored as binary data in the database, as well as the newly created time. It means that it will be a “new” file
    in the SharePoint site regardless of where it comes from.
    Per my knowledge, the only way I can suggest is that you will need to create a client desktop application for the file uploading, which will be a more general way not only for
    uploading a file, but also when we need to migrate files between different systems.
    Thanks

  • Trying to get Xinet XMP data

    Hi Everyone,
    I'm trying to create a slug script for InDesign CS3 that retrieves custom Xinet metadata from a custom XMP panel.  I was able to complete this task in Illustrator CS3 by using the following code to connect to the XMP data:
    // load the library:
    if (ExternalObject.AdobeXMPScript == undefined) {
         ExternalObject.AdobeXMPScript = new ExternalObject('lib:../../Frameworks/AdobeXMPScript');
    // get the custom client field:
    var docXmp = new XMPMeta(docRef.XMPString);
    var xmpClient = docXmp.getProperty('http://ns.xinet.com/ns/xinetschema#',"CLIENT");
    alert(xmpClient);
    I've noticed that the Frameworks file for InDesgin is AdobeXMP.framework and not AdobeXMPScript, and the XMPMeta object does not apparently exist in AdobeXMP.framework. 
    Am I missing something here?  I find it very odd that Adobe would use different libraries across their applications for something that's supposed to be a standard.  How can I retrieve the Xinet data?
    Thanks,
    -Dave

    I figured it out.  Here's the solution:
    var myClient = docRef.metadataPreferences.getProperty('http://ns.xinet.com/ns/xinetschema#', "CLIENT");
    alert(myClient);

Maybe you are looking for