Weekly Aggregation based on everyday date

Hi All,
i have a table with 3 columns. Id , MeasureDate,Measure. Here   Id +MeasureDate as primary key.  In this table i want add a column Avg.  if i am running today 2/12/2014,2/5/2014,01/29/2014 and so on avarage value will be replaced in the
Avg column .
Give some ideas.
Thiru

Seems you need Running Averages. This sample code will help you understand.
CREATE TABLE #RunAVGTestData(ID INT PRIMARY KEY, VALUE INT)
INSERT #RunAVGTestData
SELECT 1,RAND()*10 UNION
SELECT 2,RAND()*10 UNION
SELECT 3,RAND()*10 UNION
SELECT 4,RAND()*10 UNION
SELECT 5,RAND()*10 UNION
SELECT 6,RAND()*10
SELECT a.id, a.value, (SELECT AVG(b.value)
FROM #RunAVGTestData b
WHERE b.id <= a.id)
FROM #RunAVGTestData a
ORDER BY a.id;
Please use Mark as Answer; if my reply solved your problem. Use Vote As Helpful if a post was useful. |WWW.FACEBOOK.COM/SONNIE.HIM | |+91-9742-354-384 |

Similar Messages

  • Code for the the previous Sat and Sat four weeks prior based on todays date

    Hi All...
    I am looking for a bit of code to work out the following  in a variable customer exit...)
    Based on system (todays) date calculate the actual calendar day for
    1. the last previous Saturday
    2. the Saturday 4 weeks prior to 1.
    i.e  todays date is for instance 12th September 2011 then results code needs to produce is
    1. 10/09/2011
    2. 13/08/2011
    Thanks in advance,
    Steve;)

    Hi Steve,
    You can follow the logic below:
    data:
    l_date like sy-datum, **TODAY
    l_date2 like sy-datum, **First Saturday
    l_date3 like sy-datum. **Saturday 4 weeks before
    data:
    l_daynr like HRVSCHED-DAYNR.
    *Get today's date
    l_date = sy-datum.
    *Gey today's day (Monday, Tuesday, etc.)
    CALL FUNCTION 'HRIQ_GET_DATE_DAYNAME'
    EXPORTING
    langu = 'EN'
    date = l_date
    IMPORTING
    daynr = l_daynr.
    CASE l_daynr.
    *If it is Monday
    WHEN 1.
    -Subtract 3 days for the first saturday
    CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
    EXPORTING
    id_date = l_date
    id-operator = '-'
    is_duration = 3
    IMPORTING
    ed_date = l_date2.
    -Subtract 31 days for the saturday 4 weeks before
    CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
    EXPORTING
    id_date = l_date
    id-operator = '-'
    is_duration = 32
    IMPORTING
    ed_date = l_date23.
    *If it is Tuesday
    WHEN 2.
    .... -> Like monday
    *If it is Wednesday
    WHEN 3.
    *If it is Thursday
    WHEN 4.
    *If it is Friday
    WHEN 5.
    *If it is Saturday
    WHEN 6.
    *If it is Sunday
    WHEN 7.
    ENDCASE.
    Regards,
    Dilek

  • FI-CA Open Items based on key date Business Content

    Hi,
    I am using BI content infocube 0FC_C07 to extract contract account open items data. Our requirement is to do the data load weekly basis based on key date.
    I have enhanced the extractor and i can see data for the enhanced fields in RSA3. But now, i am not sure how to load data into BI.
    At the infopackage level(PSA level)  there are 2 mandatory fields (DateID(LAUFD) and Additional Identification Characteristic(LAUFI)). Do i need to change the date every week manually? I have to create a process chain to automate the dataloads.
    Also, i need to use counters for Each unique Contract Account and Contract Account Document .
    For the contract Account Document number , i am thinking to us this formula(If contaract document item =1 then document counter =1 otherwise 0). But i am not sure how to count each single contract Account?
    Your advise will be appreciated.
    Thanks,
    Priya

    Hi Priya,
    Go to InfoPackage selection tab.
    Now in the Type select 6 which is for ABAP Routine.
    This will open the ABAP Editor.
    Write your code there.
    Sample code.
    data: l_idx like sy-tabix.
    DATA : from_date type sy-datum,
           to_date type sy-datum,
           month(2) type n.
    read table l_t_range with key
         fieldname = 'IDATU'.
    l_idx = sy-tabix.
    *if current date is suppose 14th April 2008, then this routine should
    *pick values from 1st jan 2008 till
    14th April 2008
    clear month.
    month = sy-datum+4(2).
    if month = '01'.
    month = '10'.
    endif.
    if month = '02'.
    month = '11'.
    endif.
    if month = '03'.
    month = '12'.
    endif.
    if month GT '03'.
    month = month - 3.
    endif.
    concatenate sy-datum+0(4) month '01' into to_date.
    l_t_range-low = to_date.
    l_t_range-high = sy-datum.
    l_t_range-sign = 'I'.
    l_t_range-option = 'BT'.
    modify l_t_range index l_idx.
    p_subrc = 0.

  • Get weeks based on start date

    Hi ,
    i need a query that will determine the weeks based on start date.
    if the table consists of:
    vDate vAmount
    06/25/2007 100
    06/27/2007 200
    07/04/2007 400
    If one enters start date as 6/25/2007 , amounts should be broken out in 7 day increments.
    Result should be
    week1 300
    week2 400
    where week1 should be from 6/25/2007 to 07/01/2007,
    week2 should be from 07/02/2007 to 07/08/2007
    and start date is not always on a Monday or Sunday...
    any idea?
    thanks in advance

    try this...
    SQL> with rt as
      2  (select 'week'||(trunc(l/7,0)+1) wk_no,to_char(trunc(sysdate)+l,'dd-Mon-yyyy') dt,to_char(trunc(sysdate)+l,'Day') "Day" from
      3  (select level-1 l from dual connect by level <= 367) where trunc(sysdate) between trunc(sysdate) and add_months(trunc(sysdate),12)),
      4  xx as
      5  (select '06/25/2007' vdate, 100 vamount from dual union all
      6  select '06/27/2007', 200 from dual union all
      7  select '07/04/2007', 400  from dual)
      8  select wk_no,sum(vamount) from
      9  (select (select wk_no from rt where dt = to_date(vdate,'MM/DD/YYYY')) wk_no,vamount from xx)
    10  group by wk_no;
    WK_NO                                        SUM(VAMOUNT)
    week1                                                 300
    week2                                                 400
    SQL>
    SQL> select 'week'||(trunc(l/7,0)+1) wk_no,to_char(trunc(sysdate)+l,'dd-Mon-yyyy') dt,to_char(trunc(sysdate)+l,'Day') "Day" from
      2  (select level-1 l from dual connect by level <= 367) where trunc(sysdate) between trunc(sysdate) and add_months(trunc(sysdate),12);
    WK_NO                                        DT          Day
    week1                                        25-Jun-2007 Monday
    week1                                        26-Jun-2007 Tuesday
    week1                                        27-Jun-2007 Wednesday
    week1                                        28-Jun-2007 Thursday
    week1                                        29-Jun-2007 Friday
    week1                                        30-Jun-2007 Saturday
    week1                                        01-Jul-2007 Sunday
    week2                                        02-Jul-2007 Monday
    week2                                        03-Jul-2007 Tuesday
    week2                                        04-Jul-2007 Wednesday
    week2                                        05-Jul-2007 Thursday
    .

  • Creating parameter based on Submit Date from Remedy ITSM

    I am new to creating Crystal Reports and I am using Crystal Reports XI. I am pulling information from BMC Remedy ITSM through an ODBC connection. I have created a report from HPD_Help_Desk that pulls the Incident Number, Submit Date, Submitter, Owner and Description. I am not having any problems pulling the information from the tables. The issue that I am running into is creating a new parameter field that can be used so that when the people that will be running this report can pull information based on a date range of the submit date. When the report is run, it pulls the datetime from Remedy ITSM in a mm/dd/yyyy hh:mm:ss format with AM or PM on the end. I have created a parameter named Date Range that has a static list of values. The Type of the parameter is Date Time. The Value Field is Submit_Date. I have selected true for allowing custom values and allowing range values. The objective is to have the person running the report type in the datetime range such as Start of Range Value: 11/22/2009 00:00:00AM and End of Range Value: 11/28/2009 23:59:59PM so that they get all data for Incidents created from the start of the day on the 22nd to through the end of the day on the 28th providing 1 weeks worth of data. I know selection criteria can be used to run for the previous full week, but this will not help if people want to check on historical data. When the parameter is added to the report, it requests the datetime ranges be entered in a yyyy-mm-dd hh:mm:ss format. I have entered in datetime ranges and it will not filter the data. I receive data back for all dates even outside the range requested. I have attempted to change the format of the Submit Date within the report to match what the parameter is asking for and receive the same results. Any help would be greatly appreciated. Thank you in advance.

    Thank you for the feedback Carl. Again, I am new to this, so please be patient with me. I am not sure what you mean about adding the parameter to the record selection formula. I have drug the parameter field into the report so that it will prompt for parameters before running, but I do not think that is what you are talking about. Please advise.
    To your question about the Submit Date field in the report, when I open up the report and I point at the field for Submit Date the popup shows HPD_Help_Desk.Submit_Date (DateTime). That being the case, I think the answer to your question is that the data type of the data being returned is DateTime. Thanks again for the assistance.

  • Analysis for Office 1.4.7 Can't do calculation based on HANA data

    Hi,
    We are currently using Analysis for office 1.4.7 based on HANA data. When we try to use calculation, we got following error.
    Nested exception. See inner exception below for more details:
    Unable to execute SQL statement (CREATE_COLUMN_VIEW) \: CREATE OLAP SCENARIO '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <cubeSchema operation="createCalculationScenario" version="3">
        <calculationScenario name="POC-zmlf-fico-histcopatma-pkg/CALV_SHCOPATMA_MUL_1408373161431" schema="_SYS_BIC">
            <scenarioHints createInMemoryOnly="false"/>
            <dataSources>
                <analyticDataSource view="POC-zmlf-fico-histcopatma-pkg/CALV_SHCOPATMA_MUL" schema="_SYS_BIC" name="columnViewSource">
                    <attributes>
                        <allAttribute/>
                    </attributes>
                </analyticDataSource>
            </dataSources>
            <calculationViews>
                <aggregation defaultViewFlag="true" name="defaultAggregation">
                    <inputs>
                        <input name="columnViewSource"/>
                    </inputs>
                    <viewAttributes>
                        <allViewAttribute/>
                    </viewAttributes>
                    <keyfigures>
                        <allKeyfigure/>
                         <calculatedKeyfigure datatype="double" aggregationType="sum" name="[Measures]_Formula1">
        <formula>("G_QVVNTW" - "ZKGPSTD")</formula>
    </calculatedKeyfigure>
                    </keyfigures>
                </aggregation>
            </calculationViews>
        </calculationScenario>
    </cubeSchema>' (ERROR [S1000] [SAP AG][LIBODBCHDB32 DLL][HDBODBC32] General error;258 insufficient privilege: Not authorized)
    Currently the account we use has select access to "_SYS_BIC". What else do we need in term of priviledge?
    Thanks.
    Terry

    Hi Tammy,
    We can do calculations now with Create Scenario" system privilege.
    The issue I am facing was what objects we can do calculation and what objects I can't or should not.
    Example:
         I can do calculation between kilos and Net Weight(Kilos) since both are quantity. Once I bring in Gross Profit at Standard which is dollar value into my calculation, I got "No applicable data found".

  • Logical column - Aggregation - based on dimensions

    Hi,
    Can anyone explain the working of the aggregation based on dimension functionality. I understand it is different from level - based measures.
    Thanks in advance.
    - Priti

    Hi priti,
    Aggregation based on dimension .
    Hav a look at this you get an idea http://gerardnico.com/wiki/dat/obiee/measure_level_based
    UPDATED POST
    Sorry i gave you the wrong link.This is what your looking for
    http://gerardnico.com/wiki/dat/obiee/aggregation_based_on_dimension
    follow this etiquette as your new http://forums.oracle.com/forums/ann.jspa?annID=939
    Cheers,
    KK
    Edited by: Kranthi on Feb 24, 2011 12:20 AM

  • Use of filters and aggregations based on hierarchy nodes in an update rule

    Hello,
    I need to calculate some indicators from a ODS (BW 3.5) that contain raw data to another one that will contain indicators. These figures are the results of the use of filters and aggregations based on hierarchy nodes (for example: all sales accounts under a node).
    In fact, this is typically a query but I want to store these figures, so I need
    I understood I have to use a start routine. I never did that before.
    Could you provide me with easy-to-understand-for-newbies examples of:
    - filtering data based on the value of an infoobject (value must be empty, for example)
    - filtering and aggregation of data based on the appartenance to hierarchy nodes (all sales figures, ....)
    - aggregation of the key figures based on different characteristics after filtering of these
    Well, I am asking a lot ...
    Thank you very much
    Thomas

    Please go through the following link to learn more on aggregates:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e55aaca6-0301-0010-928e-af44060bda32
    Also go through the very detailed documentation:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/67efb9bb-0601-0010-f7a2-b582e94bcf8a
    Regards,
    Mahesh

  • Creation profile with weekly aggregation

    Hello amigos!!
    I created a creation profile for foreign suppliers by doing weekly aggregations.
    I have the following problem... for de deliveries from today to the future the print layout show the aggregation weekly (weekly format), that is fine.
    But the deliveries in the past the print layout show them with day format. And is also required in Week format.
    what I missed? what I need to do to fix it=

    Hi,
    Settings for the Creation Profile
    You make the following settings in Customizing for Purchasing under Scheduling Agreement ® Maintain Release Creation Profile for Scheduling Agreement with Release Documentation.
    General Parameters
    For JIT delivery schedules, you select Changed or next date. For forecast (FRC) delivery schedules, you select Next date only.
    For JIT schedules, you specify that backlogs and immediate requirements are determined.
    Aggregation Horizons
    For JIT schedules, you specify daily aggregation and enter 10 workdays as End. For FRC schedules, you choose monthly aggregation and enter 180 workdays as End.
    This has the effect that JIT delivery schedules show the daily quantities for the next 10 workdays and FRC schedules the monthly quantities for the next 180 workdays (9 months à 20 workdays).
    Creation Periodicity
    You specify weekly creation for JIT schedules and monthly creation for FRC schedules.
    Tolerance Profile
    You specify 10 days as the checking period for JIT schedules, since this corresponds to the release horizon. You enter 5% as upper and lower tolerance limits and choose Overall check.
    In your case JIT SCHEDULE IS VALID. I hope this will clear your issue.

  • ABAP Get Week Number for a Given Date.

    Hi All,
    I want to calculate week number for given date.
    SAP has provided function modules like DATE_GET_WEEK.. Etc are giving week number. taking default start day as Monday. But for my requirement is calculate week number based on start day as Sunday.
    Please let me know if we have any custom logic ??
    Thanks & Regards
    Vasu Yadav

    Hi Vasu,
    SAP standard functionality takes MONDAY as first day.
    But if you want then you can change it to SUNDAY by implementing BADI CALENDAR_DEFINITION. Create a new implementation for method IF_CALENDAR_DEFINITION~GET_FIRST_DAY_OF_WEEK and assign value as SUNDAY.
    Hope it solves your problem.
    Thanks
    Saurabh Kabra

  • FM to get the previous sunday date based on current date(sy-datum)

    hi all,
    Is there any function module to get the previous sunday date based on current date(sy-datum)?
    Regards,
    Kapil Sharma
    Moderator Message: Basic date related questions are not allowed
    Edited by: Suhas Saha on Sep 19, 2011 11:39 AM

    Hi,
    There are function modules to find out the current day of the week depending on sy-datum. These are as below:
    1. DATE_COMPUTE_DAY - Returns a number indicating what day of the week the date falls on. e.g. Monday is returned as a 1, Tuesday as 2,...., Sunday as 7.
    2. RH_GET_DATE_DAYNAME  - Returns the day based on the date provided, e.g. Monday, Tuesday,..., Sunday.
    Using any of the above, if you can find out the current day, then you can calculate and compute the date of the previous Sunday.
    My observation is that using the first FM might make the calculation simpler.
    Hope this is of help to you.
    Regards,
    Shayeree

  • Exception aggregation based on two characteristic

    Hi Guys
    i have enhanced the datasource  i.e 2lis_12_vcitm for sales order qty
    now i have to get the unique qty based on order no and item no to devide it to get a ratio
    how can i do the exception aggregation to take one value based on two characteristics that is order no and item no
    Regards
    Amiya

    hi 
    Exception aggregation based on 1 characteristics i know very well but my requirement is different i have to get unique data based on two characteristics i.e
    order    item   qty
    100      10      5
    100      20      3
    100      10      5
    100      10      5
    100      20      3
    200     10       15
    200     10       15
    now i want to get 5 for order 100 and item 10
    and 3 fro 100 and 20
    i think by exception aggregation its not possible is there another way?

  • Calculate week no based on financial year

    Hi
    Financial year starts with 01-Apr . I need to calculate week no based on 01-APR(financial year) not 01-Jan
    for each date. Is there a way to calculate based on this

    It works for all year long :-)
    SQL> ed
    Wrote file afiedt.buf
      1  with testdata as (
      2     select date '2011-04-01' + 7 * (level-1) dt from dual
      3     connect by level <= 60
      4  )
      5  --
      6  -- End of test data
      7  --
      8  select
      9  to_char(dt,'YYYY-MM-DD') the_date,
    10  to_char(add_months(dt,-3),'WW') fiscal_week,
    11  to_char(add_months(dt,-3),'IW') iso_fiscal_week
    12  from testdata
    13* order by dt
    SQL> /
    THE_DATE   FI IS
    2011-04-01 01 52
    2011-04-08 02 01
    2011-04-15 03 02
    2011-04-22 04 03
    2011-04-29 05 04
    2011-05-06 06 05
    2011-05-13 07 06
    2011-05-20 08 07
    2011-05-27 09 08
    2011-06-03 09 09
    2011-06-10 10 10
    2011-06-17 11 11
    2011-06-24 12 12
    2011-07-01 13 13
    2011-07-08 14 14
    2011-07-15 15 15
    2011-07-22 16 16
    2011-07-29 17 17
    2011-08-05 18 18
    2011-08-12 19 19
    2011-08-19 20 20
    2011-08-26 21 21
    2011-09-02 22 22
    2011-09-09 23 23
    2011-09-16 24 24
    2011-09-23 25 25
    2011-09-30 26 26
    2011-10-07 27 27
    2011-10-14 28 28
    2011-10-21 29 29
    2011-10-28 30 30
    2011-11-04 31 31
    2011-11-11 32 32
    2011-11-18 33 33
    2011-11-25 34 34
    2011-12-02 35 35
    2011-12-09 36 36
    2011-12-16 37 37
    2011-12-23 38 38
    2011-12-30 39 39
    2012-01-06 40 40
    2012-01-13 41 41
    2012-01-20 42 42
    2012-01-27 43 43
    2012-02-03 44 44
    2012-02-10 45 45
    2012-02-17 46 46
    2012-02-24 47 47
    2012-03-02 48 48
    2012-03-09 49 49
    2012-03-16 50 50
    2012-03-23 51 51
    2012-03-30 52 52
    2012-04-06 01 01
    2012-04-13 02 02
    2012-04-20 03 03
    2012-04-27 04 04
    2012-05-04 05 05
    2012-05-11 06 06
    2012-05-18 07 07
    60 rows selected.ISO Week (IW) works with a different way of defining week 01. Using IW April 1st will become week 52. You will have to decide if that is correct according to your finance department :-)

  • Is there any way of dragging and dropping an iCal event showing in week view across to a date in the left sidebar monthly calendar?

    Hi, Im not a frequent forum poster, as most of my questions can be found already answered on them!
    This is a question Ive had for a long time and it amazes me that no-one else seems to ask it. I check at each OS upgrade but its never there...
    Is there any way of dragging and dropping an iCal event showing in week view across to a date in the left sidebar monthly calendar?
    I was able to do this years ago in MS Outlook, and utilized it all the time when I needed to push things back, now I have to open the event and select an new date in the drop-down calendar for each & every event I want to move to a new month at the end of the month.
    If its definitely not possible, how to you ask apple to consider including it - it doesnt seem like a particularly difficult task.
    Thankyou
    Andrew.

    Andrew,
    Is there any way of dragging and dropping an iCal event showing in week view across to a date in the left sidebar monthly calendar?
    No, but you can use cut/paste. Cut (⌘X) the event, then click on the week where you want to move the event, and Paste (⌘V).
    If you have a suggestion for Apple to change that method use: Apple - Mac OS X - Feedback.

  • Problem creating a 'used sources' list based on EXIF data in InDesign CS5

    Hello everyone,
    I recently started to use InDesign CS5 to work on school projects. These projects regularly require us to have a list of sources, not only for citations and referenced work, but also for images. As I sometimes make quite long documents, keeping track of what image is where, and where I got it from, gets tedious.
    I had the idea of generating a caption based on EXIF data, which I'd move to the pasteboard, and group it with the image. The text in the caption has a seperate, numbered paragraph style. On one of the last pages, I generate a table of contents, which the numbered paragraph style selected. I chose to display it using another paragraph style, without page numbers.
    What I want to have as the end result is:
    Table of contents
    1. <Title>. <Author> (<Creation Date>). Retrieved <Date Placed> through <Description>
    The captions display correctly, as shown above in the body of the table of contents. The table of contents itself however, shows only the numbering in front of it, and not the variables.
    I already tried converting the live captions to static captions, but that doesn't work. Does anyone have an idea how to solve this?

    Hello everyone,
    I recently started to use InDesign CS5 to work on school projects. These projects regularly require us to have a list of sources, not only for citations and referenced work, but also for images. As I sometimes make quite long documents, keeping track of what image is where, and where I got it from, gets tedious.
    I had the idea of generating a caption based on EXIF data, which I'd move to the pasteboard, and group it with the image. The text in the caption has a seperate, numbered paragraph style. On one of the last pages, I generate a table of contents, which the numbered paragraph style selected. I chose to display it using another paragraph style, without page numbers.
    What I want to have as the end result is:
    Table of contents
    1. <Title>. <Author> (<Creation Date>). Retrieved <Date Placed> through <Description>
    The captions display correctly, as shown above in the body of the table of contents. The table of contents itself however, shows only the numbering in front of it, and not the variables.
    I already tried converting the live captions to static captions, but that doesn't work. Does anyone have an idea how to solve this?

Maybe you are looking for

  • Firefox 9.0.1 hangs on startup after update (OSX 10.6.8), even in safe mode.

    I shut down Firefox because some parts of the www.washingtonpost.com site no longer displayed (icons), and Firefox automatically installed the update on restart. Then the "Well this is embarrassing..." Restore Session screen popped up, but the progra

  • Reg:RFC &TRFC

    hi, we have 2 clients 800 and 810 in the same server. we have created a function module in 800 and wrote a simple select statement to fetch data from VBAK table and made it REMOTE.And i am fetching the data from 810 to  update a table in 800.     Whe

  • Rotten Apple?

    I need help please and a lot of convincing.... I bought an iMac in 2009 which runs Mountain Lion 10.7.5. We have 2 iPads and 3 iPhones in the house. I have a Time Capsule and several Airport Extremes which provide a roaming Wifi network in our house.

  • Flashback query

    Hi When i use flashback_transaction_query to retrive undo sql it shows it does not exit. Can anyone guide me. Imran

  • I can't pass the icloud terms and conditions page after updating ios7

    Hi, I need urgent help! I can't pass the icloud terms and conditions page after updating ios7 I've tried agree disagree and every other button i could press but it just wouldn't go pass the page Is there anyone who can help me with it?