Function to Substract No of weeks

Hi,
I have a week column called Wk_Value in which i have data from 1990-W01 to 2012-W52.
In one of my filters, I want Wk_value between 2012-W3 to 2011-W28. I want a function where in i can subtract 26 weeks from 2012-W3 so that i can get 2011-W28.
Appreciate your inputs.
Thanks & Regards,
Amrutha.

Amrutha wrote:
Hi,
The datatype is Varchar2.
I am not that aware of the database version. I suppose it is 11g.Jeez, why do people insist on storing dates as strings.
You'll likely have to do some string manipulation to get it converted to a date e.g.
SQL> ed
Wrote file afiedt.buf
  1  with t as (select '2012-W03' as dt from dual)
  2  select (to_date(substr(dt,1,4),'YYYY')+(7*substr(dt,7,2))) - (7*26)
  3* from t
SQL> /
(TO_DATE(SUBSTR(DT,1
24-JUL-2011 00:00:00

Similar Messages

  • AGO function in OBIEE to display weekly sales data of this year vs last yea

    All,
    I would to create an analysis that display this year sales numbers vs last year by weekly
    I was able to do this at month level by specifying the offset value to 12 to the AGO function in repository.
    I am not able to do at week level.
    Can someone please help?
    Thanks

    Check the W_DAY_D or W_WEEK_D for number of weeks per year, validate the year/4 then its leap year then 53
    Use this in ago function at <<Number of Periods>>.
    I think you have to go for 53 based on these tables some times 54.

  • Function module that will return week  details

    Anyone know Sap FM that will return Week  details(as below)for a given start and end dates (similar to the function module HR_99S_INTERVAL_BETWEEN_DATES which  returns details for a month) independent of factory calendar
    I am expecting
    Inputs
    Start Date  - 01/01/2005
    End Date   -  05/05/2006
    outputs
    WK YEAR BEGDA      ENDDA      
    02 2005 01/03/2005 01/09/2005 
    03 2005 01/10/2005 01/16/2005 
    04 2005 01/01/2005 01/23/2005
    Thank, Bill

    Hi Bill,
    FM is <b>GET_WEEK_INFO_BASED_ON_DATE</b>
    Here's a test-program for your requirement:
    REPORT zforum09 LINE-SIZE 255.
    PARAMETERS:fdate  LIKE sy-datum DEFAULT '20050103',
               tdate  LIKE sy-datum DEFAULT '20060505'.
    DATA : BEGIN OF itab OCCURS 0,
           week LIKE scal-week,
           from LIKE sy-datum,
           to LIKE sy-datum,
           END OF itab,
           next LIKE sy-datum.
    next = fdate.
    WHILE tdate > itab-to.
      CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
           EXPORTING
                date   = next
           IMPORTING
                week   = itab-week
                monday = itab-from
                sunday = itab-to.
      next = itab-from + 7.
      APPEND itab.
    ENDWHILE.
    LOOP AT itab.
      WRITE:/ itab-week+4(2),
              itab-week(4),
              itab-from,
              itab-to.
    ENDLOOP.
    Regards Andreas

  • DECODE(SUM Function Transtype substract

    Hi,
    I am trying to subtract transaction types from a FACT table using SUM & DECODE functions. I need to substract Transtypes (10201, 10206, 10207, 10212) - (10202, 10206, 10207, 10212)
    Query
    SELECT
    D0.campaign_id,
    NVL((NVL(((SUM( DECODE((FACT.transtype_key),(10201),(FACT.Occurred)   , (10206), (FACT.Occurred)   , (10207), (FACT.Occurred)   , (10212), (FACT.Occurred), ( 0) ) ) ) ) , (NULL)) ), ( 0))  -  SUM( DECODE((10202),(FACT.Occurred) , (10206),(FACT.Occurred) , (10207),(FACT.Occurred) , (10212),(FACT.Occurred) ) ) )
    FROM EPIMART.MESSAGES_CME_0_V FACT, EPIMART.campaign_0_V D0
    WHERE FACT.TRANSTYPE_KEY IN (10202, 10207, 10219, 10218, 10210, 10212, 10204, 10201, 10206, 10211)
    AND D0.Campaign_key = FACT.campaign_key
    AND (D0.campaign_id = '33205')
    GROUP BY D0.campaign_id
    SQL*Plus: Release 11.2.0.2.0 Production on Wed Dec 26 19:13:26 2012
    Copyright (c) 1982, 2010, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Thanks,
    Soph
    Edited by: Soph on Dec 26, 2012 4:15 PM

    Soph wrote:
    Hi Frank,
    So 10206, 10207, and 10212 count as both positive and negative? Only positive
    Why not just say "I need to substract Transtype 10201 - 10202"? That's what I'm trying to accomplish
    Do all the other transtypes mentioned in the WHERE clause (10204, 10210, 10211, 10218 and 10219) count as 0? some of them have count
    Below is a sample output of data the query produced. the unique campaign_id retrieves the number of unique member number in the FACT table then sum per transaction type key event... I basically need the sum of transtype_keys ==> (10201, 10206, 10207, 10212) - (10202, 10206, 10207, 10212)
    CAMPAIGN_ID     SENT     TARGETED     BOUNCED     VIEWED     DUPLICATE     UNDELIVERED     DO_NOT_SOLICIT     UNSUBSCRIBED     NOT_SENT_NO_TRANSLATE     FIELD_IGNORED
    33205     1,221,188     1,296,690     108,223     214,256     75,265     183,725     38     1     199     0
    Desired Result
    Targeted = Sent + DO_NOT_SOLICIT_CME + NOT_SENT_NO_TRANSLATE_CME + Duplicate
    MINUS
    Delivered = Targeted - Do Not Solicit - Duplicate - Bounced - Not Sent No Translate
    SENT 10201
    DO_NOT_SOLICIT_CME 10207
    NOT_SENT_NO_TRANSLATE_CME 10212
    DUPLICATE 10206
    Let me know if something is unclear
    Thanks,
    Soph
    Edited by: Soph on Dec 27, 2012 8:35 AMEverything is unclear. Do you need to have targeted, whatever you call the stuff substracted form targete and delivered appear in the query or just the single result of the subtraction? If just the single number then the whole thing is equivalent to 10201 - 10202. Perhaps this helps explain our confusion, since you did not give a translation for 10202, I labelled it NOT_SURE.
       (SENT     + DUPLICATE + DO_NOT_SOLICIT_CME + NOT_SENT_NO_TRANSLATE_CME)
    - (NOT_SURE + DUPLICATE + DO_NOT_SOLICIT_CME + NOT_SENT_NO_TRANSLATE_CME)everything except sent and not_sure cancel out in the two sums, so why bother adding them in in the first place. Just substutute some actual numbers in that to prove it to yourself.
    Further, you are only using 5 different values of transtype_key in the calulation, yet your in list has 10 different values. Why select those out of the table just to throw them away? It looks to me as if you are showing only part of a larger effort, and the missing bits are what confuses us.
    John

  • Need a function Module to retrive the weekly absence data from PNP logical

    hi all,
    i have generated a report for absence data according to my report when u enter the start date and end date and absence type it will give u the list of employees and starting date and end date and absence hours.
    But my client wants the report in following format:
    YEAR    week number      number of absence hourse in that week
    2006  -
        WEEK  -
                  HOURS
    infotype is pa2001.
    thx in advance.
    Sunil

    Hi Sunil,
    I think you have to use zreport.
    Regards,
    kumar

  • Need a Function Module for Week Calculation

    Dear Experts,
      I want a function module which calculate the week number.
      Suppose for date 04.05.2010
      week is 19...........
       i want to fetch through function module.
    i have already tried function module like GET_WEEK_INFO_BASED_ON_DATE & DATE_GET_WEEK
      throgh both function module output is come out is 18.
      but i need 19.
      when i pass 02.01.2010
    then it giving 53 week of 2009.
    plz. help me as soon as possible.
    Thanks,

    Jan 2 2010 was indeed 53rd week of 2009, so SAP FMs are returning right value. I would strongly recommend to consult your functional consultant before assuming Jan1 2010 as week 1 of 2010.
    [quote from wikipedia|http://en.wikipedia.org/wiki/ISO_8601#Week_dates]
    'If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.'
    Regards,
    Pawan.
    Edited by: Pawan Kesari on May 4, 2010 4:56 PM

  • Nested AGO function in OBIEE

    Hi ,
    I am not able to understand the reason behind using Nested AGO functions.
    In one of the logical columns (Sales LastYear LastWeek) the mapping was in the following fashion:
    Ago(Ago("Core"."Fact - Retail Inventory Receipts"."Receipts Retail" , "Core"."Date Retail Fiscal Calendar"."Fiscal Week" , 1) , "Core"."Date Retail Fiscal Calendar"."Fiscal Week" , 52)
    Is it the same as writing a ago function with period of 53?
    Like this:
    Ago("Core"."Fact - Retail Inventory Receipts"."Receipts Retail" , "Core"."Date Retail Fiscal Calendar"."Fiscal Week" , 53)
    Please help me understand.
    Thanks for your help.
    Anand

    Hi Anand,
    This is how I interpret the function:
    Display the fact 'Receipts Retail' for the current fiscal period minus one fiscal week minus 52 fiscal weeks. So basically: Display the fact for the current fiscal period minus 53 fiscal weeks.
    However, since the column is named 'Sales LastYear LastWeek', this definition is a bit tricky. The formula is only true, if the fiscal year consists of 52 fiscal weeks (most of the time this is correct, but you never know!). I would prefer changing the second part of the forumula to Fiscal Year, 1:
    Ago(Ago("Core"."Fact - Retail Inventory Receipts"."Receipts Retail" , "Core"."Date Retail Fiscal Calendar"."Fiscal Week" , 1) , "Core"."Date Retail Fiscal Calendar"."Fiscal Year" , 1)
    This will substract a fiscal week and a fiscal year.
    I hope this helps.
    Regards,
    Marco Siliakus

  • Weekly view missing!!!

    Alright… i am really happy with my iphone, BUT there is a major function missing in the calendar function. There is no weekly view! I hope the smart people at apple will soon come up with an update...

    I don't know if this will ever carry over to the iPhone Calendar, but the iPad Calendar seems to have a week view mode:
    "Calendar
    +iPad makes it easy to stay on schedule by displaying day, week, month, or list views of your calendar. You can see an overview of a whole month or the details of a single day. iPad even shows multiple calendars at once, so you can manage work and family schedules at the same time."+

  • How to get week number and day in my result?

    hi experts, i have given the data is ID and DATE(yyyymmdd),i want to get output like ID,DATE,WEEKNO,YEAR,MONTH,DAY. how to get this output.
    thanks & regards
    vijay

    In a routine transformation you can call function
    DATE_GET_WEEK
    to get the week number from the date.
    To determ the others, use the substring
    YEAR = DATE(4)
    MONTH = DATE+4(2)
    DAY = DATE+6(2)

  • Email icon and function disappears 3 seconds after opening a PDF in Acrobat 8.

    Using Adobe Acrobat 8 with updates applied, when opening .pdf files the email function disappears 3 seconds after the file opens.  I have had this program in my PC for years, and this functionality worked up until last week when it disappeared.
    I have been informed that this program is no longer supported by telephone, and that I need to upgrade to gain access to support.
    I have reinstalled the program and the problem persists.
    Any suggestions would be appreciated.

    Hi Jason,
    I would recommend you to do a selected startup and then enable the programs one by one to isolate which program might be causing this.
    Please refer the KB: Restart Windows in a modified mode | Windows 7, Vista for selective startup of Windows.
    Regards,
    Anoop

  • How to determine the month from the week number?

    Hi all,
    in a routine i have the week number in a year and i need to find the month but i don't know the correct FM to use for this.
    Is there anyone that had to face a similar problem?
    I'm considering that to determine the month it will be used the first day of the week since there are weeks belonging to 2 different months...
    Thank you
    Stefano

    Hi
    If you have a Fiscal Year Variant determined for the week you can use function module PERIOD_DAY_DETERMINE by passing week,fiscal year and fiscal year variant for the week which will return fist and last date.So based on last data you can determine the month.
    Regards
    Srilaxmi

  • FM for week/date/time

    Hi ,
              Is there any FM for to get a week from date and time. I am looking for a function module which gives a week starts from SUN 6PM and week ends
    SUN 6PM by passing a date.
    Thanks,
    Vind.

    hi,
    Use GET_WEEK_INFO_BASED_ON_DATE.or
    HR_IE_NUM_PRSI_WEEKS- Will return the number of weeks between two dates.
    CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
    EXPORTING
    DATE = I_EKET-EINDT
    IMPORTING
    WEEK = OUTWEEK
    * MONDAY =
    SUNDAY = I_EKET-EINDT.
    IF YOU PASS THE DAY (I_EKET-EINDT) IT WILL GIVE THE WEEK INFORMATION AND SUNDAY(1ST DAY).
    Regards,
    Santosh

  • FM for getting all days of week

    Hi,
    When I enter todays date FM should bring up all dates in a week.
    Eg: today if user enters 02/04/2009
    It should give me values 3/29 , 3/30 , 3/31, 01/04,02/04 etc..
    Do we have any FM for this?
    Rgds
    Praveen

    Hi Praveen
    In the below mentioned funtion modules you can get almost all type of days & weeks calculations...
    For your requirement just do this
    "To calculate week Start & End date
            CALL FUNCTION 'HRWPC_BL_DATES_WEEK_INTERVAL'
              EXPORTING
                DATUM                = SY-DATUM " Current date (ITAB DATE)
                WEEK_PST             = '0'
                WEEK_FTR             = '0'
             IMPORTING
               BEGDA                = STR_WEEK_DATE  " Week start date
               ENDDA                = END_WEEK_DATE. " Week end date
    then
    day1 = STR_WEEK_DATE
    day2 = day1 + 1.
    day3 = day2 + 1.
    till day7...
    "To calculate week no for  particular date
        CALL FUNCTION 'DATE_GET_WEEK'
          EXPORTING
            DATE         = SY-DATUM " any date
          IMPORTING
            WEEK         = WEEK_NO ." Week no for particular date
    "To calculate week Start & End date
            CALL FUNCTION 'HRWPC_BL_DATES_WEEK_INTERVAL'
              EXPORTING
                DATUM                = SY-DATUM " Current date (ITAB DATE)
                WEEK_PST             = '0'
                WEEK_FTR             = '0'
             IMPORTING
               BEGDA                = STR_WEEK_DATE  " Week start date
               ENDDA                = END_WEEK_DATE. " Week end date
    "To calculate Months ending date
              CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
                EXPORTING
                  I_DATE = SY-DATUM " Any date
                IMPORTING
                  E_DATE = END_MONTH_DATE. " Month's ending date
    "to calculate particular day No for any give date.
        CALL FUNCTION 'DATE_COMPUTE_DAY'
          EXPORTING
            DATE = SY-DATUM " any date
          IMPORTING
            DAY  = DAYNO1. " particular day no.
    "To calculate particular day name with the day no
        CALL FUNCTION 'BKK_GET_DAY_OF_WEEK'
          EXPORTING
            I_DAY       = DAYNO " week day no.
          IMPORTING
            E_WDAY      = CURRENT_DAY_NAME. " Week day name for the week day no.
    " to Calculate the next week
        CALL FUNCTION 'NEXT_WEEK'
          EXPORTING
            CURRENT_WEEK = WEEK_NO "Current week,
          IMPORTING
            NEXT_WEEK    = WEEK_NO. " Next week
    " to calculating starting date of the week
        CALL FUNCTION 'WEEK_GET_FIRST_DAY'
          EXPORTING
            WEEK = WEEK_NO "week No
          IMPORTING
            DATE = STR_WEEK_DATE. " Starting date of the particular week
    "To Calculate particular day No for any given date
            CALL FUNCTION 'DAY_IN_WEEK'
              EXPORTING
                DATUM = STR_WEEK_DATE " Any date
              IMPORTING
                WOTNR = DAY. " Day no for a giveN date
    Hopw this solves your Problem
    Thanks & regards,
    Dileep .C

  • Function Module which will take Wekk No & Return date range (from & To dat)

    Hello everyone,
    I need a Function Module which will take Week No as an input Parameter & return me the date range
    (From date & To date of that week) .
    Thanks in advance!
    Cheers!
    Moderator message: date calculation questions = FAQ, please search before posting.
    Edited by: Thomas Zloch on Nov 2, 2010 5:25 PM

    Hi,
         Please write the below logic..
    data : v_date11 type sy-datum,
              monday    type sy-datum,
              sunday  type sy-datum,
              v_count1 type i .
    *v_count1 = 20 * 7.            "   Say U want details for 20th week , or give a parameter for week and multiply with 7*
    v_date11 = '20100101'.     "   take the starting day of the year ....
    v_date11 = v_date11 + v_count1.   " add to the date
    CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'   <-- call this FM
    EXPORTING
       DATE          = v_date11
    IMPORTING
      WEEK          = WEEK
       MONDAY        = MONDAY <-- will have the week starting day
       SUNDAY        = SUNDAY
    Regards,
    Srini.

  • Routine based on Function Module

    Hello All,
    i have to write code for a routine using a custom function module that is created previously.
    the function has input parameter IN_YEAR_WEEK  and output parameter EN_WEEK_1 ,  EN_WEEK_2.
    this routine is in the transformation between cube and open hub between the 0calweek of the cube and a custom field znum_week in the open hub.
    the input parameter of the function like 201005 (the fifth week in 2010 year) is the same value that i will have in the 0calweek of my cube and give in output 2 parameters between 0 and 5 that's mean the number of week in the month.
    the value between 0 and 5 should be puted in the znum_week field
    if the function return value between 1 and 5 i should have duplicate records in the open hub file.
    can you give me please some advice how should be my abap coding for this routine.
    should i use start routine? or routine of the single field?
    thanks
    Bilal

    Hi ALL,
    i have created this code for start routine to duplicate records in my open hub, can you tell me please if the logic is correct?
    data: v_week_1 like n.
    data : v_week_2 like n.
    DATA: vn_tabix LIKE sy-tabix.
    data: wa_temp LIKE SOURCE_PACKAGE.
    LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>.
    CALL FUNCTION ' ZIV_DP_FUNC_NUM_WEEK_LA '
        EXPORTING
            IN_YEAR_WEEK = <SOURCE_FIELDS>-/bic/0calweek
        IMPORTING
          EN_WEEK_1  = v_week_1
           EN_WEEK_2  =  v_week_2.
    If v_week_1 between 1 and 5 and v_week_2 = 0
    <SOURCE_FIELDS>-/bic/0calweek = v_week_1.
    MODIFY SOURCE_PACKAGE INDEX vn_tabix FROM < SOURCE_FIELDS>.
    Endif.
    Else
    If  v_week_1 between 1 and 5 and v_week_2  between 1 and 5
    <SOURCE_FIELDS>-/bic/0calweek = v_week_1.
    MODIFY SOURCE_PACKAGE INDEX vn_tabix FROM < SOURCE_FIELDS>.
    MOVE <SOURCE_FIELDS> to wa_temp.
    wa_temp-/bic/0calweek = v_week_2.
    APPEND wa_temp TO SOURCE_PACKAGE.
    Endif.
    REFRESH: wa_temp.
    thanks a lot
    Bilal

Maybe you are looking for