Previous Available date in a column

I Have a colum date and a amount. If select a date i need to fetch the previous avaialble amount
In the below case
WITH table_1 AS
(select '700' amount,'01/01/2011' date1 from dual union all
select '800' amount ,'12/23/2010' date1 from dual union all
select '900' amount, '11/31/2011' date1 from dual
select * from table_1;
if my where clause for date = '12/23/2010' then the amount should be '0' as no previous day amount avaialble.
if my where clause for date = '01/01/2011' then the amount should be '800' as the avaialble previous date is '12/23/2010'
if my where clause for date = '11/31/2011' then the amount should be '700'' as the avaialble previous date is '01/01/2011'
Please help
Edited by: user10285699 on Jan 24, 2011 5:47 PM

Hi,
user10285699 wrote:
... WITH table_1 AS
select '1' day, '10' id1,'100' amount,'12/30/2010' date1,'null' amount_pre_day from dual union all
select '1' day,'20' id1 ,'200' amount , '12/20/2010' date1 ,'null' amount_pre_day from dual union all
select '1' day, '30' id1, '300' amount, '10/28/2011' date1,'null' amount_pre_day from dual
select * from table_1;
The second day i need to calculate the previous AVAILABLE day amount and update another column "amount_pre_day"
WITH table_1 AS
(select '2' day, '10' id1,'400' amount,'12/31/2010' date1, '100' amount_pre_day from dual union all
select '2' day, '20' id1 ,'500' amount ,'12/22/2010' date1,'200' amount_pre_day from dual union all
select '2' day, '30' id1, '600' amount, '10/31/2011' date1,'300' amount_pre_day from dual
select * from table_1;
The tihrd day i need to calculate the previous AVAILABLE day amount and update another column "amount_pre_day"
WITH table_1 AS
(select '3' day, '10' id1,'700' amount,'01/01/2011' date1, '400' amount_pre_day from dual union all
select '3' day, '20' id1 ,'800' amount ,'12/23/2010' date1,'500' amount_pre_day from dual union all
select '3' day, '30' id1, '900' amount, '11/31/2011' date1,'600' amount_pre_day from dual
select * from table_1;Thanks for posting the sample data.
Always post the results you want from the sample data, too, and say what version of Oracle you're using.
Are those 3 different sets of sample data? I'm very confused by what you want.
Why is everything a string, including the word 'null'? In particular, it's a really bad idea to store dates in VARCHAR2 columns; you should use a DATE column instead.
What date is '11/31/2011' supposed to be?
My best guess as to what you mean is:
"I have the following table:
{code}
WITH table_1 AS
select '1' day, '10' id1, '100' amount, DATE '2010-12-30' date1, null amount_pre_day from dual union all
select '1' day, '20' id1, '200' amount, DATE '2010-12-20' date1, null amount_pre_day from dual union all
select '1' day, '30' id1, '300' amount, DATE '2011-10-28' date1, null amount_pre_day from dual union all
select '2' day, '10' id1, '400' amount, DATE '2010-12-31' date1, '100' amount_pre_day from dual union all
select '2' day, '20' id1, '500' amount, DATE '2010-12-22' date1, '200' amount_pre_day from dual union all
select '2' day, '30' id1, '600' amount, DATE '2011-10-31' date1, '300' amount_pre_day from dual union all
select '3' day, '10' id1, '700' amount, DATE '2011-01-01' date1, '400' amount_pre_day from dual union all
select '3' day, '20' id1, '800' amount, DATE '2010-12-23' date1, '500' amount_pre_day from dual union all
select '3' day, '30' id1, '900' amount, DATE '2011-11-30' date1, '600' amount_pre_day from dual
{code}
But I don't actually want to supply the amount_pre_day column; I want to compute that from the amount column of the previous row (where date1 determines what that means) for the same id1."
If that's what you meant, here's one way to get it:
SELECT       t.*
,       LAG (amount) OVER ( PARTITION BY  id1
                              ORDER BY         date1     -- or maybe day
                   )               AS calc_pre_day
FROM       table_1   t
ORDER BY  id1
,            date1
;Output:
D ID AMO DATE1       AMO CAL
1 10 100 30-Dec-2010
2 10 400 31-Dec-2010 100 100
3 10 700 01-Jan-2011 400 400
1 20 200 20-Dec-2010
2 20 500 22-Dec-2010 200 200
3 20 800 23-Dec-2010 500 500
1 30 300 28-Oct-2011
2 30 600 31-Oct-2011 300 300
3 30 900 30-Nov-2011 600 600As you can see, the last column (calc_pre_day) is the same as amount_pre_day.

Similar Messages

  • Previous day date to pick up

    i want to pick up the previous latest date from a column. that means
    if i have a column name batch_id and the dates avaiable are
    batch_id Previous date
    27-06-07 26-06-07
    26-06-07 25-06-07
    25-06-07 23-06-07 -----saturday date out here
    Its a sunday therefore no business for this day and therefore no entry for this day.
    23-06-07 22-06-07
    please let me know how to achive this through SQL
    Thanks in advance

    Is this?
    select batch_id
      ,case when to_cahr(batch_id,'fmday','nls_date_language=american') = 'monday'
        then batch_id-3
        else batch_id-1
       end  previous_date
    from your_table
    ;But, how do you want to treate holidays?

  • Sharepoint 2007 - Creating a form to capture timesheets data, but need to track updates to previously submitted data

    Hi,
    We are using a basic version of Sharepoint 2007 and do not have access to InfoPath. I have created a list to allow team members to submit their weekly time on specific activities.  How do I go about tracking any changes to previously submitted data?
    For instance, a team member enters 5 hours for Activity 1 and submits on April 1.  on April 10 they realize they submitted too few hours and want to go in to edit the 5 hours to 12 hours.
    From a reporting perspective we already pulled a report (export to excel) and have the 5 hours listed for April 1. If the user goes in to edit their time sheet from April 1, we don't want the data to just override the 5 hours, we want some sort of flag to
    show the hours went from 5 to 12 hours.  How do we do this?
    As a work around, I added a question at the beginning of the survey/list asking is this a new submission or an edit. I thought if they select edit and were taken to a screen that allowed them to select the date (April 1), the activity and the new hours that
    I would have all of the previous data plus these 3 columns with the additional data: "Edit", "Activity 1", "12".  Instead the original data was over written and all I show are blanks for the previous questions and the edited
    info ("Edit", "Activity 1", "12").
    What suggestions do you have so that I can maintain the integrity of the original data and flag for my Project Manager which data needs to be changed in previous reports.
    Thanks in advance!
    AA

    I think the best way to answer your question would be to create a simple form and try various submissions. Be aware that unless the e-mail system is controlled, e-mail submission is not recommended due to client configuration issues of e-mail. Your question sounds like online submission would already be something you are comfortable with. In that case you can submit form data in 3 different ways: HTML, FDF, or XML. It can also be submitted as a PDF by saving the form, but that does not sound like what you need and also gets into issues of whether folks are using Reader or Acrobat.
    Also be careful (or try both) about using forms from within Acrobat and the forms created by the link in Acrobat to Designer. Once you go to Designer with the form you can not come back for editing in Acrobat. Normally you would create the basic form in a word processor or layout tool and then add the form fields in Acrobat (or Designer if that is preferred).
    I will let others address the anonymous and yet confirmation check issue.

  • Displaying data from multiple columns into a single line graph

    Post Author: hollowmatrix
    CA Forum: WebIntelligence Reporting
    Hey,I have an issue with the WEBI reporting.I have a data source that has multiple columns say ( month1, month2, month3, month4,.....month 12, month 13, ....month24) with the sales data for each month.Now say I call the month 1 to month 12 as "current year", and call month 13 - month 24 as "previous year".I want to put a prompt in the report which allows  me to select between "current year" and "previous year".Based on the prompt value we get a graph of the sales vs month ....as in if we select  "current year", then we get a graph of the sales Vs time( remember that the sales data for each month is in a different column.)and if we select  "previous year" then we get a graph of the sales Vs time for previous year..( sales vs time for Month 13, month 14, month 15....month 24).I am not able to pull data from multiple columns into a single object that I can use to populate the graphs.Any help on the same will be appreciated .   

    Hi,
    <p>
    please click
    here (asktom) and look for the words "how about the other way round"
    </p>

  • How to show a report for 'Previous Month' Data

    Hi Gurus,
    I have a requirement, where i have to default my report to show previous month data.
    Scenario:
    My prompts by Default are set to CURRENT (current year,quarter,month). once the user logs in, the report should display data for month 'Nov' instead of 'Dec'.
    I tried using TIMESTAMPADD() in the formula , but it didn't work, though i don't see any error. Not sure if i 'm missing something.
    Is there a way to achieve this.I 'm using OBIEE 11.1.1.6.
    Any help is highly Appreciated ! Please.
    Thanks,
    Ramya

    From what you wrote I am assuming the user can manually save the report results to the Excel file.
    If your report uses ALV Grid it is possible to export the data to a spreadsheet (one of the functions available in the ALV tool bar).
    If you have used WRITE statements it is also possible to save the output as a spreadsheet (menu System -> List -> Save), but the latter will not produce as nice a spreadsheet if the data don't form a matrix. In other words, some work may be necessary in the spreadsheet afterwards before it has the format your user wants.

  • SSRS 2008R2 : Not able to use Previous aggregrate function in matrix columns cell

    Hi Expert,
    I have used a matrix tablix in my report. It is working fine. But when I am trying to use Previous aggregrate in one matrix column cell I get the below error:
    The use of previous aggregrate function ia a tablix cell with in 'Tablix1' is not supported.
    Please help me regarding that.
    Thanks Rana

    Hi Rana,
    In your scenario, you use previous function in the “Data” cell, right? Previous function cannot be used in the overlapping parts of row group and column group. One workaround of this issue is use custom code to get the previous value.
    Public Shared previous as Integer
    Public Shared current as Integer
      Public Shared Function GetCurrent(Item as Integer) as Integer
         previous=current
         current=Item
         return current
      End Function
      Public Shared Function GetPrevious()
         return previous
      End Function
    Then you can use the expression below in the “Data” cell to get the previous value:
    =Code.GetCurrent(fields!Score.Value) & "-Previous-" & iif(Code.GetPrevious()=0,"",Code.GetPrevious())
    If you have any questions, please feel free to ask.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Get a quarter out of data for a column chart

    Who can help me with this challenge?
    I want to create a column chart with four quarters in the current year and one column with the rest later in time.
    One project can have multiple output data. They are separated by an ;
    The notation of the outputdata can be a date (d-m-yyyy), a month (mm-yyyy) or a quarter (Q1-yyyy).
    This is by example the available data.
    Project              outputdata
    Project 1           1-4-2014
    Project 2           03-2014;Q4-2014;Q2-2015
    Project 3           25-09-2014;Q1-2015
    The data I want to get for the column chart is:
    Project              outputdata                    columnchart
    Project 1           1-4-2014                       Q2-2014
    Project 2           03-2014                        Q1-2014
    Project 2           Q4-2014                       Q4-2014
    Project 2           Q2-2015                       2015 and later
    Project 3           25-09-2014                   Q3-2014
    Project 3           Q1-2015                       2015 and later
    I hope that someone can help me in the right direction.
    Thanks in advance,
    Els

    Adding to what Frank has already suggested, try something on these lines:
    Something like this?
    SQL> ed
    Wrote file afiedt.buf
      1  with x2 as(
      2     select 'proj1' proj, '1-4-2014' op, NULL chart from dual UNION ALL
      3     select 'proj2' proj, '03-2014' op, NULL chart from dual UNION ALL
      4     select 'proj2' proj, 'Q4-2014' op, NULL chart from dual UNION ALL
      5     select 'proj2' proj, 'Q2-2015' op, NULL chart from dual UNION ALL
      6     select 'proj3' proj, '25-09-2014' op, NULL chart from dual UNION ALL
      7     select 'proj3' proj, 'Q1-2015' op, NULL chart from dual
      8  )
      9  select
    10     proj,
    11     op,
    12     case
    13     when regexp_like(op,'((\d{1}|\d{2})-(\d{1}|\d{2})-(\d{4}))')
    14     then
    15             'Q'||TO_CHAR(TO_DATE(op,'dd-mm-yyyy'),'Q')||'-'||TO_CHAR(TO_DATE(op,'dd-mm-yyyy'),'yyyy')
    16     when regexp_like(op, 'Q\d{1}-\d{4}')
    17     then
    18             CASE
    19             when SUBSTR(op,-4,4) > 2014
    20             then
    21                     SUBSTR(op,-4,4)||' and later'
    22             else
    23                     op
    24             end
    25     when regexp_like(op, '\d{2}-\d{4}')
    26     then
    27             'Q'||TO_CHAR(TO_DATE(op,'mm-yyyy'),'Q')||'-'||TO_CHAR(TO_DATE(op,'mm-yyyy'),'yyyy')
    28     end
    29* from x2
    SQL> /
    PROJ       OP                   CASEWHENREGEXP
    proj1      1-4-2014             Q2-2014
    proj2      03-2014              Q1-2014
    proj2      Q4-2014              Q4-2014
    proj2      Q2-2015              2015 and later
    proj3      25-09-2014           Q3-2014
    proj3      Q1-2015              2015 and later
    6 rows selected.

  • Can't delete previous unread messages in hub pinch view via select previous (hold date line)

    Happily running OS 10.2.1.2141 on my Z10 (STL100-3). I was thrilled to see the hub's Pinch Selection Criteria option in 10.2.1 but did not have the occasion to try it. Then this weekend, my mailbox got flooded with email notices from our alert system and I was facing having to delete hundreds of emails the old tedious way, multi-select each email one at a time and hit the delete option.  Well, that's when I tried to use the hub's new pinch selection option to "hide" my read messages. I then held the date line to select all the previous messages and hit the delete option which asked my if a really wanted to delete those messages. I confirmed by choice and poof! nothing happened. I tried several times to no avail, even trying with flagged messages. It looks like you can't delete messages while in Pinch Selection view if you select them via the Select previous (hold date line) method. It does work if you select/multi-select the messages manualy but what's the point then?....
    So, unless i'm doing it wrong, this appears to be a bug.
    Regards,
    Francis.....   

    fpaquin wrote:
     that should be the point of the pinch selection criteria and you're select by sender.... let's see if anyone can reproduce the "bug" on their handsets or better yet, BlackBerry confirms it's a bug or poor design......
    when I pinch and hold a date bar, I get the trash can... do you not?
    fpaquin wrote:
    Yup, that's the tedious way I've always used, ok for a few emails, unacceptable for hundreds of emails.....
    Oh, yea for hundreds. Do you get hundreds each day you need to delete?
    Once you get caught up on your deleting, then your daily upkeep should be a reasonable low effort.
    Anyways, that's how it works.
    If you feel it is an OS issue... what OS are you on?
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Need to show Previous months data in report

    Hi All,
    I have a crystal report 2011 which shows monthly Cash data. It has 3 other columns like Previous 3 months cash data, previous 6 months cash data, Previous 12 months cash data in report.
    My report also has two parameters- start date and end date. If I give Start date as 1/1/2012 and end date as 12/31/2013 (two years date range) then correct data comes in all columns and for 2013 year, correct data is coming for Previous 12 months column. But if I give only one month date range like start date as 1/1/2013 and end date as 01/31/2013, then it is not showing correct data for these 3 columns - Previous 3 months cash data, previous 6 months cash data, Previous 12 months cash data. Ideally as per requirement, it should calculate previous months data regardless of parameter values and put data in respective columns.
    Any help/suggestion? Any trick which can help me to show correct data in all columns no matter what date range or months I am taking in parameters.
    Is it mandatory to have previous 12 Months data in report to calculate column-Previous 12 months Cash data?
    Thanks,
    Remi

    Hi Remi,
    You can try like this:
    I have given a some suggestions i.e You just take one parameter only because u can imagine 3 columns previous data display correctly i.e From Date
    Month parameter is also a alternate option.
    For Ex: Column1: From Date - 90 Days/3 Months  - we get the three months previous data correctly etc.
    Finally, create a stored procedure that returns the required columns and does all the calculations on the database side.
    Follow abhilash suggestion as well.
    Useful threads: Crystal Report Parameter Issue
    Pull Last 6 months of data
    Month to date data for Previous month
    How to find current month, previous month Net Sales by means of formula?
    Thanks,
    DJ

  • How do I get numbers to automatically add the next date down a column in numbers?

    How do I get numbers to automatically add the next date down a column in numbers?

    Hi Dd,
    If you want the next date automaitcally  filled in when you add a row to the bottom of the table, you can use a formula.
    Here's an example, done in Numbers 2.3 (Numbers '09). The method is basically the same in Numbers 3.
    Formulas in row 3:
    B3: =B2+1
    C3: =C2+7
    D3: =D2+14
    These have been filled down to the last row of the table.
    The same table is shown below after three rows have been added by dragging the Row control handle (below the tab for row 7) down. No changes other than adding thse three rows were made by the user.
    Note that rows 1 and 2 are header rows, and that row 2 contains the starting date for the seraies of date in each column. In the formula, the number at the end tells Numbers how many days to add to the previous date to get the next date.
    Autofill of the formula requires that every non-header cell located above the cell into which the formula is to be filled contains the same formula.
    Regards,
    Barry

  • Upto previous period data

    Hi
    how to get upto previous month data
    if select aug-11 then i get upto jul-11 data for the aug-11
    how to do this
    i have gldate,startdate,enddate

    Hi
    thanks for ur reply but
    but my requirement is different
    actually i have some date columns
    my condition is gldate<startdate
    my values are
    gldate values are like 1/31/2011,2/28/2011,3/31/2011,4/30/2011,5/31/2011 ...
    startdate values 1/1/2011,2/1/2011,3/1/2011,4/1/2011,5/1/2011 ..
    periodname --jan-11,feb-11,mar-11  likethsi
    if i select periodname nov-11 then
    startdate is 11/1/2011 and gldate is 11/30/2011
    my condition is gldate<startdate its false then all gives 0's
    my requirement is if i select periodname nov-11 then startdate is 11/1/2011 then iget the amount for the all gldate values <startdate
    startdate i compare all gldate values its not filtered
    then this condition get upto oct-11 values
    i nees for nov-11 values are upto oct-11 values sum
    plz how to dothis
    if ur not understand plz reply to me

  • Determination of Delivery/Availability dates for a SO

    Hello Gurus,
    .....I am an SAP-PP consultant , my question is..
    .....I have a sales order created by user on Sep 15 for 840pcs .  We do not have any stock of this material
    1. MD04 screen shows availability date as Oct 7 .
    2. I selected the SO in this screen and branced to the schedule line of this Material  . It had 2 line items
    One line item was on Oct 7th, Order qty 840pcs,rounded-840,confirmed qty is ZERO
    second line item was on Nov 11th, order qty and rounde qty is zero, but confirmed qty is 840 .
    ...I want to know why system is proposing 2 line items for the same requiremnst?
    ..I want to know how has sytem arrived at these date .(the inhouse prodn time is only 1day)
    ..i branched into shiiping info for first line item it shows Delivery date,GI date,Loading date,Materila availabality date,Transportation plan date as ...Oct 7th..How did it arrive at this date.
    Appreciate if GURUs can give a detailed reply cos i m not familiar with SD terminology.
    THNX in ADVANCE
    HKR

    The way that I associate this situation is the following:
    10/7 - there is a requirement to ship qty 840 on this date.  Per this requirement, there is 0 confirmed qty to actually ship the goods on this date.  This is also schedule line 1.
    11/11 - the system is proposing this date to ship qty 840 and is confirming for this date based on either an incoming purchase order or the planned delivery time set in the material master.  There is no requirement for this date because the requirement is already set for the 10/7 date.  This is schedule line 2.
    MD04 is known as the stock/requirements list.  As previously stated, you have a requirement to ship qty 840 on 10/7 and it would appear as such within the stock/requirements list.  This isn't the date it will actually ship, it merely lists the requirement to fulfill that qty for the 10/7 date.  MD04 is primarily for the planning side from my understanding.
    CO09 is the availability overview and will show the two dates 10/7 - qty 0 confirmed and 11/11 - qty 840 confirmed.  Lets say you get a shipment on 10/15.  When rescheduling runs, on 10/15, the system will delete schedule line 2 and update schedule line 1 with the following - date 10/15, order qty 840, confirmed qty 840.
    Hope this helps.

  • Get previous bill date using SQL

    Hi,
    I am table which holds records for bill generation. I have column name gene_bill_date which is date field and it holds a value the date on which the particular bill was generated.
    Now I am trying to get previous bill date, not the current bill date. I can to Max(gene_bill_date) to get current bill date, but how do I get previous bill date?
    thanks

    Hi,
    Sorry, it's unclear what you're asking.
    You didn't post any sample data, so I'll use the scott.emp table to illustrate. Let's say we're interested in deptno=30 only, just to reduce the output from 14 rows to 6.
    If, for every row, you need to know the most recent gene_bill_date before the one on that row, you can do something like this:
    SELECT     ename
    ,     hiredate
    ,     LAG (hiredate) OVER (ORDER BY hiredate)     AS prev_hiredate
    FROM     scott.emp
    WHERE     deptno     = 30
    ;Output:
    ENAME      HIREDATE    PREV_HIREDA
    ALLEN      20-Feb-1981
    WARD       22-Feb-1981 20-Feb-1981
    BLAKE      01-May-1981 22-Feb-1981
    TURNER     08-Sep-1981 01-May-1981
    MARTIN     28-Sep-1981 08-Sep-1981
    JAMES      03-Dec-1981 28-Sep-1981Are you only interested in the 2 most recent dates in the whole result set?
    If so, do a Top-N Query , like this:
    WITH     got_r_num     AS
         SELECT     ename
         ,     hiredate
         ,     RANK () OVER (ORDER BY hiredate  DESC)     AS r_num
         FROM     scott.emp
         WHERE     deptno     = 30
    SELECT     *
    FROM     got_r_num
    WHERE     r_num     <= 2
    ;Output:
    ENAME      HIREDATE         R_NUM
    JAMES      03-Dec-1981          1
    MARTIN     28-Sep-1981          2 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Run the query with previous weeks date automatically

    Hi Guyz,
    I need to  dynamically populate the previous weeks  date value every week,
    i.e Run the query every Monday automatically, with previous weeks date value .
    Is there any SAP Exit which I can use ??
    Regards,
    Ravi
    Edited by: Ravi Srinivas on Aug 4, 2009 1:40 PM
    Edited by: Ravi Srinivas on Aug 4, 2009 1:52 PM

    Ravi,
    If you are thinking of re-running the previous week's queries automatically in the front-end, then U. Tummers is correct.  You can create new columns alongside your existing query if you so wish and use your restrictions with an offset sepending on how far back you'd like to go.
    Best,
    Philips

  • VA01 change Delivery and Material Staging/Availability Date when vacation

    Hi Gurus,
    When I create a new order in VA01 for a day my company is on a period of vacation, I would like to change automatically the Material Staging/Availability Date and Delivery date to the last working day before vacations to avoid late deliveries.
    I am trying to find the custo point where to do it, but I don't find it. Do you have any suggestions?
    Thank you in advance.

    Thanks Andy,
    We maintain the factory calendar, so the problem is how the system is calculating this availability date.
    For example, if we have a week of vacation and we get an order for Wednesday, the system calculates the first day after this vacation week as the day we can deliver the product. In our example would be on next Monday.
    What we would like to do is that the system calculates as a delivery date the last working day before the vacation week, in our example would be on the previous Friday. So then we can avoid those late deliveries we are having now.
    I don't know how or where to customize that.
    I accept any suggestions.

Maybe you are looking for