Average for last 12 months

hi,
i have a column amount. i need to find the avg of it for last 12 months excluding current month.
I have got a query to find it .but it is adding current month also with it.
AVG(SUM(amount)) OVER (ORDER BY ACCOUNT_MONTH_NO
ROWS BETWEEN 12 PRECEDING AND 0 FOLLOWING) rolling_avg,
please help me to write a query as i am a naive user of oracle.

Like..
SQL> select * from test;
ACCOUNT_NU ACCOUNT_MONTH_NO     AMOUNT
ACC1                      1        100
ACC1                      2        200
ACC1                      3        300
ACC1                      4        400
ACC1                      5        500
ACC1                      6        600
ACC1                      7        700
ACC1                      8        800
ACC1                      9        900
ACC1                     10       1000
ACC1                     11       1100
ACC1                     12       1200
12 rows selected.
SQL> select account_month_no,amount,
  2     avg(amount) over(order by account_month_no rows
  3            between 12 preceding and 1 preceding) avg
  4  from test
  5  where ACCOUNT_NUMBER  = 'ACC1';
ACCOUNT_MONTH_NO     AMOUNT        AVG
               1        100
               2        200        100
               3        300        150
               4        400        200
               5        500        250
               6        600        300
               7        700        350
               8        800        400
               9        900        450
              10       1000        500
              11       1100        550
              12       1200        600
12 rows selected.Post sample data and expected output, so that we can help you better

Similar Messages

  • Calculate NWC (Average for last 4 Month)

    Do someone know how to calculate NWC (Average for last 4 Month) using @AVG?FIX ("2002", Jan)     "Net Working Capital (Average for last 4 Month)" = @AVG(SKIPMISSING, "Net Working Capital", "2001"->Oct,"2001"->Nov, "2001"->Dec, "2002"->Jan);ENDFIXIn my case, we split the Year and Month Dim in our outline.Can this script work in under our situation???Thanks

    Try usingFIX ("2002", Jan) "Net Working Capital (Average for last 4 Month)" = @AVG(SKIPMISSING, "Net Working Capital"->"2001"->Oct,"Net Working Capital"->"2001"->Nov,"Net Working Capital"->"2001"->Dec,"Net Working Capital"->"2002"->Jan); ENDFIX

  • Why I can only download 20 photos for last month from the photostream while I have more than 3GB photos kept in iCloud? Many thanks.

    Why I can only download 20 photos for last month from the photostream while I have more than 3GB photos kept in iCloud? My iPhone was stolen and the photos in it are very precious to me. Many thanks.

    On a new device you can only download what is currently stored in "My Photo Stream" in iCloud. iCloud keeps up to the last 1000 photos, but only the photos, that have been added during the last month. Older photos may be removed, when the time is up. On other devices you may be seeing older photos as well in "My Photo Stream", that will depend on the available storage on those devices, and when the Photo Stream has been enabled on those devices, see:  My Photo Stream FAQ - Apple Support
    If you are seeing other photos in the Photo Stream on other devices, that you want to save, mail them to you from the other devices.
    Have you tried to restore your iPhone from the last iCloud backup of the old phone? The backup will contain the photos in the Camera Roll, but not the photos in Photo Stream.   iOS: Back up and restore your iOS device with iCloud or iTunes

  • STAD Report for last month

    Hi,
       Iam getting stad report for last one week,iam not getting the stad report for last month.i want to get stad report for particular day in last month.how to rectify the same.
    Thanku

    Hi,
    rsau/local/file /usr/sap/LID/DVEBMGS00/log/
    you will have to set DIR_AUDIT parameter instead of it.
    Set the following parameter with reference value:
    Parameter                                  Description                                   Reference Value
    DIR_AUDIT                  Directory for security audit files          S:\ECP-AUDIT\ECP\DVEBMGS00\ECP_security_audit_log
    FN_AUDIT                  Name of security audit file                   ECP_AUDIT_++++++++.AUD
    rsau/enable                  Enable the Security Audit Log                       1
    rsau/max_diskspace/local       Maximum space for security audit file                 2147483647
    rsau/max_diskspace/per_day  Maximum size of all security audit files per day            (If you wish, otherwise let it be default '0')
    rsau/max_diskspace/per_file      Maximum size of one single security audit file             (If you wish, otherwise let it be default '0')
    rsau/selection_slots              Number of filters to allow for the Security Audit Log            (If you wish, otherwise let it be default '2')
    rsau/user_selection              Defines the user selection method used inside kernel functions         (If you wish, otherwise let it be default '0')
    activated profile in sm19,still iam not getting audit log for last week in sm20.
    After Proper setting of Security Audit log parameters, the Application Server needs to be restarted to make the changes effective. You will only get the Audit Data since the activation of valid Security Audit parameter.
    Regards,
    Bhavik G. Shroff

  • How do I know  what transactions executed by specific user for last month

    All
    We have a request to find out  what transactions are executed by secific user
    for last couple of months.
    Is there any report in SAP would tell me ?
    Please advise.
    From
    PT.

    Hello PT,
    If you use the search for the term "How do I know what transactions executed by specific user for last month" then I guarantee you some good hits in the result, and further more detailed search terms to use...
    Cheers,
    Julius
    (this time in response to the correct thread...)

  • Average for last 7 days

    I am trying to calculate Deviation Measure for the Reports and the formula to calculate is –
    (average(last 7 days count ) – today’s count/100 )*10
    Problem here is to calculate average for last 7 days .
    I am using moving average but if I apply a filter , Moving average is calculated for the number of rows displayed whereas I want it for the number of days.
    Formula for Moving average is - MAVG(Row Count,n) where n is number of rows displayed and not number of days. Is there any possible way to do it.

    (average(last 7 days count ) – today’s count/100 )*10
    Filter( avg(col1) using date > current_date-7)) --Average for last 7 days
    Filter(count(col) using date = current_date) - today's value

  • Depreciation is not executed for last month and the period is closed. Giving Error in this Dep. Cycle.

    Hi All,
    We had a month End scenario where the depreciation for a company code is not executed for the last month and closed the period without checking it.
    While  running the Depreciation posting for this month we encounted a error that last motn period is closed. Can we do the depreciation without opening the period closed. Kindly let us know the options available.
    Regards,
    Lakshmi Narayana

    Lakshmi,
    There is no way you can post depreciation without opening the prior periods. Please discuss with your business and secure all necessarry approval, I believe the business has a process on this kind of situations. As long as it is fully documented, auditors will not find it wrong.
    This is the best time to improve your process, think of possible ways so that business will not forget to post depreciation (e.g send automatic email during 3 days before, 2 days before., 1 day before and during the day of depreciation run).
    Hope this helps.
    Thanks!
    Jhero

  • 141 GB download for last month!

    How accurate is the BT broadband usage in My BT? It says I have downloaded 141GB for the last month. Never downloaded anything near this astronomical amount when with Sky. 
    I'm on Infinity 2 so not too bothered, just very puzzled.

    BarnyG wrote:
    Further info. Just checked the router - 
    Connection time:- 26 days 02.22
    Data Transmitted/Received 2.2gb/2.0gb
    This bears no relation to My BT unless it resets each month. Does this happen?
    Is there another stats page? Some routers are known to report erroneous values in certain places - e.g. my TG582n would max out at about 4GB up and down on the detailed stats page, but would show correct values on the Internet stats page.
    Ian.
    Thanks
    Ian
    http://www.siteguru.co.uk/be/ADSL2PlusForDummies.pdf - Having ADSL issues? Then read this PDF
    Please don't click the star beside my name - too many stars makes you look like a swot!

  • Getting the data for last month of every year

    Hi,
           How to declare the date if we want to pull the data from the December of every year.
    For example if the query is run in march 2015 and they want the historical data it should pull only the data from dec 2014.
    In the same way if they ran the query in future jun 2016 and if they want to historical data it should pull only data from dec 2015.
    It should not coded manually. Please help me with date format that need to used.
    BALUSUSRIHARSHA

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    A table has to have a key to be table.  Here is my guess at a repair job: 
    CREATE TABLE Test_Data
    (pu_id INTEGER NOT NULL
      REFERENCES PU(pu_id),
     pu_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
     PRIMARY KEY (pu_id, pu_date),
     x_count INTEGER,
     y_count INTEGER);
    Identifiers are not numeric in a good schema. What math do you do with them? They are also the key in the table that models the entity they identify. Where is the PU table (and what is a PU anyway)? 
    INSERT INTO Test_Data
    VALUES
    (28, '2014-01-01', 10, 20), -- crap! No key in this mess!! 
    (28, '2015-01-01', 30, 20), -- 
    (28, '2014-12-12', 10, 20), 
    (28, '2015-02-02', 10, 20);
    A PIVOT is not a query and not even part of SQL. It is how Microsoft programmers who do not know RDBMS or have a report writer violate the tiered architecture of SQL. We also do not use XML mixed in SQL. It is a bitch to maintain, has poor performance and again
    violates the tiered architecture principle. 
    A query is not sorted because it is a table. A file in COBOL can be sorted and that seems to be what you really want to write. 
    Old COBOL love the Sybase CONVERT() string function to avoid SQL temporal data. 
    We never use SELECT * in production code; Google it. Not only are you generating code, you are generation bad code. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Month_Periods
    (month_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (month_name LIKE <pattern>),
     month_start_date DATE NOT NULL,
     month_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (month_start_date <= month_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    This will port and waste time calling string function row by row. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • FIFO showing NO difference than the Moving Average for a Month !

    Hi,
    I am trying to re-valuate my Inventory ( Moving Avg ) for April using Single Receipts ( only for the entire month ). However, when I run MRF1 ( after MRF4 & MRF3), I am NOT able to see any difference between the Moving Average Price and the Net Price.
    In other words, my Net Price is getting updated at the Moving Average Price and hence no Difference and therefore no Revaluation.
    Eg
    test Scenario
    04/02/2011 GR 200 ( Qty ) @ 2.0 == Total 200
    04/05/2011 GR 300( Qty) @ 3.0 == Total 900
    hence the updated Moving Average Price = 2.2
    04/12/2011 GI 400 (Qty) @ 2.2 == Total 800
    The Remaining Inventory should be Valued @ 2.2 = ( 100 * 2.2) = 220
    But the FIFO Revaluation on this one should be = 100 * 3.0 = 300
    However, when we execute MRF1 we are still getting it at 220 instead of 300. i.e. the Book Value and the Net Value are both 220 and the difference 0
    Has anyone across such an error ( SAP Note 74316 looks similar but, it's supposed have been addressed in Release 4.0 by using extracts and Single Receipts - we are using both )
    Any help is appreciated
    Regards
    K S
    Edited by: Kenny Sandhu on May 10, 2011 4:50 PM

    Run TCode OMWP
    Check "Single Receipt" for your FIFO method. If you cannot change, should create a new method.
    Read more http://help.sap.com/erp2005_ehp_03/helpdata/EN/47/61076e49f011d1894c0000e829fbbd/frameset.htm
    There is different result between FIFO Valuation Based on Period Receipts and Single Receipts.
    Regards,
    KimLoan
    Globalcybersoft VietNam
    Edited by: Loan Le Thi Kim on Oct 5, 2011 12:59 PM

  • MMPV for last month of year

    Hi Guru's
    I am going to open MM period through MMPV for jaunary 2010.
    i am puting period = 01 and Fiscal year 2010
    and getting error message that " 2010 is not your current cleander year.
    so what is my fiscal year in this case??
    seeking your help.
    Regards,

    Hi
    Check it out in the FI whether they opened the fiscal year in FI or not. Check with transaction OB52, whether FI has opened their periods or not.
    If not, then let them opened it first then you have to open MM period.
    Regards
    Imran

  • Ebay sent me an invoice for $61.00 for last month - why

    Ebay charges a final value fee (FVF) when you sell an item. Check your sellers account for details.

    This is an open forum, not Adobe support... You need Adobe support to cancel a subscription
    -start here https://forums.adobe.com/thread/1703848
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html
    --and two links which may provide more details, if the above links don't help you
    -http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html
    -http://helpx.adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

  • Health app: bug in daily average for sleep in year view?

    I've manually entered sleep time for everyday since August 2014 in the Health app (on iOS 8, on an iPhone 6).
    In Day, Week, and Month view, the daily average seems correct (resp. 7h49, 7h09, 7h09).
    But it is obviously wrong in the Year view (12h36mn).
    Also the graph in the Year view is wrong. (The bar for August is twice as high as the one for October for instance.)
    (I've check -3 times- that these manually entered data were correct.)
    Does anybody experience the same problem?
    Or as any idea what the bars, in the Year Graph, are supposed to represent? (daily average for each month? or total sum of sleep time for the month?)
    Thanks in advance!
    Antoine

    The Health App really serves as a conduit between a variety of other apps that wouldn't ordinarily be able to talk to each other. The App Store has a section for apps that work with Health to be able to sync data.
    You can submit feedback to Apple here:
    http://www.apple.com/feedback
    Don't stress to much if you can't find a section dedicated to Health. Pick something under "iPhone" and just make sure you explain it well.

  • Powershell Change date to the first day of last month whenever i run the script.

    If I run the script on 2/4/2013 or any other day in February I want the date to be change to 1/1/2013. I am replacing date on line 59 with this value.
    Get the content of the CMS Script.
    $CMSReport = Get-content C:\reports\CMSReport.acsauto
    Go to line 59 and replace the date for Last Month date.
    $CMSReport[58] = $CMSReport[58] -replace "([1-9]|0[1-9]|1[012])- /.- /.\d\d", [datetime]::Today.ToShortDateString() $CMSReport | Set-Content C:\reports\testCMS.acsauto
    Run the CMS script
    Invoke-Expression -command "c:\reports\testCMS.acsauto"

    PS C:\> $lastMonth = (get-date).AddMonths(-1)
    PS C:\> $firstDayOfLastMonth = get-date -year $lastMonth.Year -month $lastMonth.Month -day 1
    PS C:\> "{0:yyyy-MM-dd}" -f $firstDayOfLastMonth
    2013-01-01
    Bill
    Hello AbqBill,
    Thanks for getting me there. I am a lot closer to the final goal. I input what you suggested and I am getting different results as you. here what I did.
    $LastMonth = (Get-Date).AddMonths(-1)
    $FirstDayofLastMonth = Get-Date -year $LastMonth.year -month $LastMonth.month -day 1
    $CMSReport = Get-content C:\reports\CMSReport.acsauto
    $CMSReport[58] = $CMSReport[58] -replace "([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d", "{0:dd/MM/yyyy}" -f $FirstofLastMonth
    $CMSReport | Set-Content C:\reports\testCMS.acsauto
    I get 12/1/2013. Which bring me to 2 questions. How will this solve when it is January and it has to put last month last year? and why is it going back two month instead of 1?

  • Routine to capture last month data

    Hello Frnds,
    For a Dataload from the datasource Actual Cost Component Split(0CO_PC_ACT_10), we want to capture last month data ,
    we are planning to write a routine in infopackage level,
    using the option 6-ABAP routine, to select the last month data ,
    we have the time characteristics 0FISCPER, At present we managing the load by manually changing the selection for last month every time ,
    It would be a great help if anybody can show a sample code to select last month data,
    Thanks,
    saty

    If 'last month data' for you is equivalent to 'actual month data', post this code (corrected) into your IPACK dynamic selection:
    DATA: zyear type /BI0/OIFISCYEAR,
    ______zperiod type /BI0/OIFISCPER3,
    ______zfiscper type /BI0/OIFISCPER.
    CLEAR: zyear,
    _______Zperiod,
    _______zfiscper.
    MOVE sy-datum+0(4) to zyear.
    MOVE sy-datum+4(2) to zperiod.
    concatenate  zyear zperiod into zfiscper.
    l_t_range-iobjnm = '0FISCPER'.
        l_t_range-fieldname = '/BI0/FISCPER'.
        l_t_range-sign = 'I'.
        l_t_range-option = 'EQ'.
        l_t_range-low  = zfiscper.
        l_t_range-high = zfiscper.
        APPEND l_t_range.
    Message was edited by: Claudio Caforio

Maybe you are looking for

  • How do you fax more than one page at a time?

    How do you fax more than one page using the phone?

  • Error while trying to drop user

    Hi all, I have a user called cnos. while trying to drop the user i got error ORA-00604: error occurred at recursive SQL level 1 ORA-00942: table or view does not exist. i issue 'drop user cnos cascade' command. my oracle version is 10.2.0.4.0. I am h

  • Smart Playlists no longer working on my 4G iPod

    I have a 20GB 4G Mono iPod that is running the latest firmware version (3.1.1) and I have several Smart Playlists I use frequently with it. Before I upgraded to iTunes 7 last week these playlists would dynamically update on the iPod itself without th

  • ITunes library on a networked external hard drive

    Recently, I want to upgrade to snow leopard (finally) but was short on hard disk space on my MacBook Pro and lacking a consistent backup solution. I added a 1TB time machine to my network and mounted an external hard drive to the Time Machine for med

  • How do i display events from different calendars side by side and not on top of each other

    I must have something set up wrong on one of my calendars on my macbook pro 10.7. On one of the calendars, the events do not make space for an event from another calendar so I can see both events sidi by side in a week or day view.  When I view from