Query to get data for current week+13

Hi Friends,
I have two tables
BACKLOG_WEEK_AFTER_ATP (LE)
BACKLOG_ATP_GT_CW (RE)
** First I have to query whats the current week and year and it should come in this format ---- 2011-WK30
columns in table BACKLOG_WEEK_AFTER_ATP are:
ITEM_NUMBER      QUANTITY
1N5418                 20
1N5614                 30
1N5806SM               10
1N5811                  0
2PFF6                  60columns in table BACKLOG_ATP_GT_CW are:
ITEM_NUMBER     QUANTITY        YEAR_WEEK
1N5418                30        2011-WK30
1N5418                 5        2011-WK31
1N5614                30        2011-WK32
1N5806SM              30        2011-WK33
1N5811                20        2011-WK32
3EX473K1              20        2011-WK30My report should look like
ITEM_NUMBER    2011-WK30  2011-WK31  2011-WK32  2011-WK33  ...............till 13th week
1N5418                10         -5         -5         -5  ...............till 13t week
1N5614                30         30          0          0  ................till 13th week
1N5806SM              10         10         10         20  ................till 13th week
1N5811                 0          0         20         20  ................till 13th week
2PFF6                 60         60         60         60  ................till 13th week
3EX473K1              20         20         20         20  ................till 13th weekTo get this report i have these conditions to keep in mind.
1) If item_number not present in LE table and present in RE table then repeat what it is in RE table till 13th week
2) If item_number not present in RE table and present in LE table then repeat what it is in LE table till 13th week
3) If item_number present in LE and also present in RE table then do subtraction for RE - LE for that particular item_number till 13th week.
4) If item_number is there in LE table but not present in RE table for current_week+1(today week comes as 29th week) then repeat the same which is there in LE table. If item is found in RE table for (example 32th week) then subtract RE -LE for that particular item_number
Thanks in advance.
Regards

Hello,
If you don't need the PIVOT display, then this may help you :
with le as
(select '1N5418' item_number, 20 quantity from dual union all
select '1N5614' item_number, 30 quantity from dual union all
select '1N5806SM' item_number, 10 quantity from dual union all
select '1N5811' item_number, 0 quantity from dual union all
select '2PFF6' item_number, 60 quantity from dual ),
re as
(select '1N5418' item_number, 30 quantity, '2011-WK30' year_week from dual union all
select '1N5418' item_number, 5 quantity, '2011-WK31' year_week from dual union all
select '1N5614' item_number, 30 quantity, '2011-WK32' year_week from dual union all
select '1N5806SM' item_number, 30 quantity, '2011-WK33' year_week from dual union all
select '1N5811' item_number, 20 quantity, '2011-WK32' year_week from dual union all
select '3EX473K1' item_number, 20 quantity, '2011-WK30' year_week from dual
row_gen as (
select item_number, calc_year_week,
       row_number() over(partition by item_number order by calc_year_week) rn
from
    (select le.item_number from le union select item_number from re) item,
    (select to_char(level*7+sysdate,'YYYY-"WK"WW') calc_year_week from dual connect by level<=13) week)
select item_number, calc_year_week, calc_qty
from row_gen, le, re
where row_gen.item_number=le.item_number(+)
and row_gen.item_number=re.item_number(+)
and row_gen.calc_year_week=re.year_week(+)
model
partition by (row_gen.item_number)
dimension by (rn)
measures (calc_year_week, year_week, le.quantity le_qty,re.quantity re_qty,0 calc_qty )
rules  (
calc_qty[1]  =
    case when re_qty[cv()] is null then le_qty[cv()]
    when le_qty[cv()] is null then re_qty[cv()]
    else  re_qty[cv()]-le_qty[cv()]
end,     
calc_qty[rn>1] order by rn =
    case when re_qty[cv()] is null then calc_qty[cv()-1]
    else re_qty[cv()] - calc_qty[cv()-1]
    end           )
order by 1,2;I am not sure this is the simplest way to do it, but the results seem to match your example.
Regards,
Sylvie
Edited by: Troll35 on Jul 19, 2011 3:08 PM

Similar Messages

  • How to get data for current week and previous week using customer exit in Bex.

    Hi everyone,
    I have a scenario in which I need to display data for current week and previous week (based on "sy_datum" the program has to calculate current week and previous week) in Bex using  Customer exit. I have created one variable in Bex Query Designer and I have written code for the variable in CMOD. But it is not working fine, (I know that we can do the same by using offset value in Bex). Can some one guide me how to achieve my requirement using customer exit.
    Thanks in Advance,
    G S Ramanjaneyulu.

    Hi krishna,
    Thanks for your quick reply, can you have a look at my code,
    case i_vnam.
    WHEN 'ZPWK_CWK'.
    ranges : pre_week for sy-datum.
    data : start_date type DATS,
           end_date TYPE dats .
    ************FM TO GET FIRST DATE OF CURRENT WEEK ************************
    CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
      EXPORTING
        DATE_IN  = sy-datum
      IMPORTING
        DATE_OUT = start_date.   " WEEK FIRST DATE
    end_date = START_DATE + 6.   " WEEK LAST DATE
    END_DATE   = START_DATE - 1.   " PREVIOUS WEEK END DATE
    START_DATE = START_DATE - 7.   " PREVIOUS WEEK START  DATE
    **********PREVIOUS WEEK DATES IN PRE_WEEK******************
    pre_week-SIGN   = 'I'.
    pre_week-option = 'BT'.
    pre_week-LOW    = START_DATE.
    pre_week-HIGH   = END_DATE.
    APPEND  pre_week.
    CLEAR : START_DATE,END_DATE.
    endcase.
    Regards,
    G S Ramanjaneyulu.

  • How to calculate start date and last date for current week

    Dear All.
    i want to calculate the start of the current week as well as the last date of the current week, our week start from Saturday and ends of Friday i.e. Saturday is the first day of the week and Friday is the last day of the week.
    How can i acheive this in universe Designer?.
    Please help...

    Hi
    the formulas in webi will be as follows
    for startdate
    =RelativeDate(LastDayOfWeek(CurrentDate());-8)
    for enddate:
    =RelativeDate(LastDayOfWeek(CurrentDate());-2)
    Regards,
    Ranganath

  • ASCP Planned orders recommendation date for current week

    Dear Experts,
    I am facing the below issue in Decentralized ASCP workbench.
    In the forecast demand date is 18-04-11, 25-04-11, 02-05-11 and so aon (Weekly buckets).
    After launching plan today (18-04-11), Recommendation in workbench are showing due dates as 19-04-11, 25-04-11, 02-05-11 and so on.
    The question here is, Why the current week demand is shifting one day (19-04-11). Business requirement is today (18-04-11).
    Appreciating your valuable soluation.
    Note:
    (We checked planning time fence. Items having the value 0, 1 are also giving the same result)
    Regards,
    Ramesh

    Sandeep Gandhi,
    Yes, ASCP can not schedule anything in the past but it will suggest planned orders for today (Plan run date) for the past demands.
    Example: Forecast Demand due date : 16-04-11.
    when we run the plan today, ASCP have to suggest planned order for today's due date (18-04-11)
    But we don't know why it is shifting to 19-04-11 (tomorrow).
    Your valuable suggests will be very helpful
    Regards,
    Ramesh

  • Get data for current month in VC from query - Urgent

    Hi all,
    I have designed a query for cube FIAR_C03 for overdue items and query output contains customer, net due date, document date, fiscal year period and amount. I want a chart for that query in VC that only contains those items in which net due date is in current month. How can i do that?
    Where I can place the condition to display only those items in vc in which net due date is in current month and how ?
    Please respond.
    Regards,
    Aisha Ishrat
    ICI Pakistan Ltd.

    Hi Aisha,
    It is possible to do with following steps:
    1. In Query Design make your field 'Net Due' filter with variable for date input (0CALMONTH for example where your date should be this format MMYYYY). Test your query and see if you input a month/year date it would would work;
    2. Build one table from output of your query (choose fields);
    3. In Visual Composer, drag your query into your board and from 'Varaiables' port  (NOT FROM INPUT) drag a line to create a Start point. As soon you realease to create 'Start' a box will ask which fields you want. Choose your date as field;
    4. Select the line between Start point a query. In Input Field assigned the following formula (DSTR(NOW(),'MMYYYY') *
    5. Deploy your model
    at this formula I said: transform NOW(), current date, in Text with format MMYYYY (012002 for example).
    It works!
    Assigned points if was helpful.
    Kind Regards,
    Gilson Teixeira

  • Query to get date range in Week

    Hello all,
    I wanted the get the results in terms of week like, if sysdate is 26/7/2007 Then
    I have to get previous 7 weeks including the week where sysdate exists.
    Results should come in this manner
    23rd to 27th 1 week
    16 - 20th July 2007 as 2nd week like this till 7 weeks
    I have a query but it is not giving in the above manner
    So please anybody can make a query as mentioned above.
    Query:
    SELECT TO_DATE(TO_CHAR(SYSDATE,'DD-MON-YYYY')) + ( ROWNUM - 6)+(ROWNUM+2)D,TO_DATE(TO_CHAR(SYSDATE,'DD-MON-YYYY')) + ( ROWNUM - 6)+(ROWNUM+2) R FROM DUAL CONNECT BY LEVEL < 6

    What do you want?
    -- A week
    select sysdate, sysdate+7 from dual;
    --A week from monday to sunday
    select nexT_DAY(SYSDATE, 'MONDAY'), NEXT_day(sysdate-7, 'SUNDAY') FROM DUAL
    BE CAREFUL MONDAY AND SUNDAY IF YOUR DDBB IS IN ENGLISH
    select
    nexT_DAY(SYSDATE, 'MONDAY'), NEXT_day(sysdate-7, 'SUNDAY'), TO_char(sysdate,'d'),
    (sysdate -TO_char(sysdate,'d')) as firstone,
    (sysdate + 7-TO_char(sysdate,'d') )as lastone
    FROM DUAL
    Message was edited by:
    cth

  • Report to get data for current_week+1 till 13th week

    Hi Friends,
    I have two tables
    BACKLOG_WEEK_AFTER_ATP (LE)
    BACKLOG_ATP_GT_CW (RE)
    ** First I have to query whats the current week and year and it should come in this format ---- 2011-WK30
    columns in table BACKLOG_WEEK_AFTER_ATP are:
    ITEM_NUMBER      QUANTITY
    1N5418                 20
    1N5614                 30
    1N5806SM               10
    1N5811                  0
    2PFF6                  60columns in table BACKLOG_ATP_GT_CW are:
    ITEM_NUMBER     QUANTITY        YEAR_WEEK
    1N5418                30        2011-WK30
    1N5418                 5        2011-WK31
    1N5614                30        2011-WK32
    1N5806SM              30        2011-WK33
    1N5811                20        2011-WK32
    3EX473K1              20        2011-WK30My report should look like
    ITEM_NUMBER    2011-WK30  2011-WK31  2011-WK32  2011-WK33  ...............till 13th week
    1N5418                10         -5         -5         -5  ...............till 13t week
    1N5614                30         30          0          0  ................till 13th week
    1N5806SM              10         10         10         20  ................till 13th week
    1N5811                 0          0         20         20  ................till 13th week
    2PFF6                 60         60         60         60  ................till 13th week
    3EX473K1              20         20         20         20  ................till 13th weekTo get this report i have these conditions to keep in mind.
    1) If item_number not present in LE table and present in RE table then repeat what it is in RE table till 13th week
    2) If item_number not present in RE table and present in LE table then repeat what it is in LE table till 13th week
    3) If item_number present in LE and also present in RE table then do subtraction for RE - LE for that particular item_number till 13th week.
    4) If item_number is there in LE table but not present in RE table for current_week+1(today week comes as 29th week) then repeat the same which is there in LE table. If item is found in RE table for (example 32th week) then subtract RE -LE for that particular item_number
    Thanks in advance.
    Regards

    User_Apex wrote:
    Hi Friends,
    I have two tables
    BACKLOG_WEEK_AFTER_ATP (LE)
    BACKLOG_ATP_GT_CW (RE)
    ** First I have to query whats the current week and year and it should come in this format ---- 2011-WK30
    columns in table BACKLOG_WEEK_AFTER_ATP are:
    ITEM_NUMBER     QUANTITY
    1N5418                     20
    1N5614                     30
    1N5806SM                 10
    1N5811                       0
    2PFF6                        60columns in table BACKLOG_ATP_GT_CW are:
    ITEM_NUMBER     QUANTITY        YEAR_WEEK
    1N5418                     30                2011-WK30
    1N5418                     5                 2011-WK31
    1N5614                     30                2011-WK32
    1N5806SM                 30                2011-WK33
    1N5811                      20                2011-WK32
    3EX473K1                   20               2011-WK30My report should look like
    ITEM_NUMBER    2011-WK30  2011-WK31  2011-WK32  2011-WK33 ------ till 13th week
    1N5418                 10             -5                -5              -5     ...............till 13t week
    1N5614                 30             30               0                0     ................till 13th week
    1N5806SM              10            10              10              20    ................till 13th week
    1N5811                   0              0               20              20   ................till 13th week
    2PFF6                     60            60              60               60  ................till 13th week
    3EX473K1                20             20              20              20  ................till 13th weekTo get this report i have these conditions to keep in mind.
    1) If item_number not present in LE table and present in RE table then repeat what it is in RE table till 13th week
    2) If item_number not present in RE table and present in LE table then repeat what it is in LE table till 13th week
    3) If item_number present in LE and also present in RE table then do subtraction for RE - LE for that particular item_number till 13th week.
    4) If item_number is there in LE table but not present in RE table for current_week+1(today week comes as 29th week) then repeat the same which is there in LE table. If item is found in RE table for (example 32th week) then subtract RE -LE for that particular item_numberNot an APEX question: use {forum:id=75} forum.
    Query to get data for current week+13

  • Query for getting data for every quarter for financial year

    Hi,
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.
    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.

    lakmesri wrote:
    Hi,
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.
    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.
    How can you get 8 quarters within a year ? I'b be concerned here.
    lakmesri wrote:
    Hi,
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.
    First, that question is really not clearly asked. Second how could it be urgent ? You even did not tell us your Oracle version, did not show any tables descr, output sample nor any effort on your side to work on.
    Nicolas.

  • Any Function Module to get date by passing week and year

    Hi,
       Is there any Function Module available to get date by passing week and year. For example, Week 24, Year 2005 and you get the date.
    Regards,
    Mira

    WEEK_GET_FIRST_DAY
    pass 'YYYYWW' (200524) to WEEK parameter it will give you the week start date
    Raja

  • Need to get data for month entered in  user prompt to prior 12months.

    Hi,
    I have a report where i need to display total amount for current month  to prior  12 months data...first column will be current month, second column is (current month-1),3rd col: (current month-2)....( current month-12).
    Is there any way I could use current date to get previous 12 months in  variables?
    For example: if  current date is 02/15/2010, I need get  data for 01/2010, 12/2009, 11/2009,....01/2009.
    For example: if I entered Month: 03  and year:2010 in prompt , then I need to get data for prior 12 months to that in the prompt for month:03?.

    The only way to do this is using restrictions on Universe... here you can have the restrictions for every month or a range using the user prompt and the system date.
    Regards

  • Not getting data for 1 field in ODS

    Hi BW Experts,
    I am loading the data from R/3 to BW.I have loaded the data through PSA.The data is available in New data field. After activating the ODS, for 1 field the data is not uploaded and in the report, the values are not displaying.
    I have checked the Transformations also. it is mapped correctly.But still i am not getting data for that field.
    Thanks,
    Siva.

    Thanks for the Update
    1. What is your Service Pack Level?
      Service Pack is 0016
    2. Are you able to see the data in PSA?
       Yes I can see the data in PSA
    3. After load, are you able to see the value in New table?
       Yes i can able to see the data in New data table
    4. Anywhere, are you doing the SORTING of Data Package?
       No I have not sorted the data Package.I have not written any coding on this
    I have not written any coding in transformation also.
    Thanks,
    Siva.

  • How do I change the start date for the week from Monday to Sunday on my iPhone 5?

    How do I change the start date for the week on iCal from Monday to Sunday on my iPhone5?

    Yes. On my new iPhone 5 the iCal week begins on a Monday not a Sunday and does not give me the option to edit in settings on the phone

  • Year To Date for Current Fiscal Year

    Hi All,
    I have installed BC variable Year To Date for Current Fiscal Year 0I_CFYTD..
    foloowing error occurs
    Variable 0I_CFYTD could not be replaced..
    Do i need to write any code or Please help.....

    Hi,
    Please check if fiscal year variant is used in the filter. Else the BC variable throws an error. Drag fiscal year variant to the filter area and set a value or variable input for the same.
    Regards,
    Satya

  • Can i add data for current month only

    can I add data for current month only?

        Knowing your plan options is important marlingut! So that we are able to provide correct information, what make and model phone are you trying to add data too? Is this device already activated on your account?
    Thank You,
    MichelleL_VZW
    VZW Support
    Follow us on Twitter @VZWSUPPORT

  • Need Monday and Friday  dates for 12 weeks.

    Hi All,
    I need a core java class which takes a curdate as argument and gives the oupt put as only monday and friday dates from that date for 12 weeks.
    For example..if u enter the date 07/06/2005.
    The ou put:
    07/06/2005 07/08/2005 and it should skips the sat&sunday.
    o7/11/2005 07/15/2005
    07/18 -07/22
    07/25 -07/29
    08/01 -08/05
    08/08 -08/12
    08/15 -08/19
    like this why because i need to diplay the data in the form of buckets.between these dates.Please help.

    Take a look at java.util.Calendar. It has all the methods you need to make your own class for this.

Maybe you are looking for

  • _Error while creating a session

    While i was creating a session i got an error. My syntax was .. create schema AUTHORIZATION aijazdb CREATE TABLE paint (paint_id NUMBER PRIMARY KEY, paint_size NUMBER, colour VARCHAR2(10) ) CREATE VIEW large_paints AS SELECT paint_id,colour FROM pain

  • "Load Driver" error while installing Win7 on Satellite C665

    My hard drive in my laptop died on me, so I got a new hard drive (Solid State) and am installing Windows 7 on it on my Toshiba (Satellite C665 model PSC55A) I don't seem to be alone in encountering this error: "A required CD/DVD drive device driver i

  • How to mirror my Ipad to a pc?

    Please help me?  My wife is a teacher and I got her a ipad 2 and she needs to use it with her smart board.  If she could mirror the ipad to her computer she would be able to use the apps that she has downloaded to her ipad.  Then the students could s

  • How to get IPv6 site prefix via Windows API?

    Hello, we need urgent help. We have to automatically configure a postgres sql server. For this reason we need to determine the IPv6 site prefix. Using windows command line this is pretty easy: netsh interface ipv6 show siteprefix We are only interest

  • Adobe reader issue: no text!

    Hi, I cannot see the text in a pdf document. I can only see frames, pictures, etc but no text at all. I tried uninstalling & re-installing Adobe reader, but it was not possible since the installation partition (directory) no longer exists, so even th