Month average

I would really like to make a query (I think that is the right word) to determine the average number of sales for each month (for example, Jan thru Dec). Not the average number of per month!
I have a table as follows:
CREATE TABLE sale
id               VARCHAR2(32)     NOT NULL,
item               VARCHAR2(32)     NOT NULL,
saledate          DATE,
PRIMARY KEY(id),
Populated with data like:
001 AAA 08-FEB-00
002 ZZZ 14-MAR-01
003 HHH 06-OCT-02
004 DDD 30-MAR-03
005 KKK 12-APR-03
006 GGG 22-SEP-04
007 BBB 15-MAR-04
008 BBB 16-MAR-04
009 SSS 17-MAR-04
010 SSS 18-MAR-04
011 BBB 19-MAR-04
I did manage to create the below query which returns the average sales per month but this is NOT want I wish for:
SELECT AVG(TOTAL)
FROM (SELECT MONTH, COUNT(MONTH) as TOTAL
FROM (SELECT TO_CHAR(saledate, 'MON') as MONTH from sale)
GROUP BY MONTH);
I would like an average output per month, example:
JAN     0
FEB     0
MAR     2
DEC     0
I have no idea...
Thanks...

Okay, you want the average of the monthly sales. You can get that by doing this:
SELECT to_char(x.month, 'MON') AS month, avg(mon_tot) AS avg
FROM   ( SELECT trunc(month, 'MM') AS month, count(*) AS mon_tot
         FROM   sales
         GROUP  BY trunc(month, 'MM') x
GROUP BY to_char(x.month, 'MON');Now your other problem is filling in the gaps for months where there are no sales. You will find Help Required for date display & mutating trigger to be helpful if you are using Oracle9i or higher, otherwise you will need to use Justin's variation.
Cheers, APC

Similar Messages

  • I want to create a formula in numbers that gives me an ongoing monthly average

    I've created a spreadsheet to track my MPG, and I'm also logging all maintenance bills too.
    What I want to do, is get an idea of how much the vehicle is costing me on a monthly average. I want this to be ongoing over several years and therefore want the spreadsheet to work out the monthly average cost over the life of the vehicle.
    How would I write a formula to do this without having to manually adjust the formula each month?

    Ahhh.  OK.  you want to see an average that is only for one months data out of a list of entries,
    E2=EOMONTH(A2, 0)
    this is shorthand for... select cell E2, then type (or copy and paste from here) the formula:
    =EOMONTH(A2, 0)
    F2=EDATE(EOMONTH(A2,0)+"1d", −1)
    D2=IF(MONTH(A2)≠MONTH(A3), AVERAGEIFS(C,A,"<="&E2, A, ">="&F2), "")
    select cells D2 the F2, copy
    select cells D2 thru F8, paste
    once you are done you can combine the formulas for columns E and F into column D.... or... you can hide columns E and F

  • Past 12 months Average!

    Hello BW Gurus,
    Can any one help me in getting past 12 months average? Do we need to write any code? Currently I am using formula key figure (period1) and text variable (zperiod1)in the Bex to calculate the past 12 months average but for some reason it is giving the wrong values.
    I am calculating as follows:
    period1 = current month-13;current month-1
    zperiod = period1/12
    period1 is not giving me the total range value of last 12 months and it is just picking the current month and dividing it by 12. Is there any work around to get this done?
    Thanks in Advance,
    Liza.

    Hi,
    Following is the code for VAR2 (current month-1), which I could find off the shelf:
        WHEN 'VAR2'.
          IF I_STEP = 1.
          DATA: L_MONTHC TYPE C LENGTH 2,
                    L_DATEC TYPE C LENGTH 2.
            L_MONTHC = SY-DATUM+4(2).
            L_DATEC = SY-DATUM+6(2).
                IF L_MONTHC > 1.
                  L_MONTHC = L_MONTHC - 1.
                  L_YEAR2 = SY-DATUM(4).
                ELSE.
                  L_MONTHC = 12.
                  L_YEAR2 = SY-DATUM(4) - 1.
                ENDIF.
            IF STRLEN( L_MONTHC ) < 2.
              CONCATENATE '0' L_MONTHC INTO L_MONTHC.
            ENDIF.
            CONCATENATE L_YEAR2 L_MONTHC INTO L_S_RANGE-LOW.
            L_S_RANGE-OPT = 'EQ'.
            L_S_RANGE-SIGN = 'I'.
            APPEND L_S_RANGE TO E_T_RANGE.
          ENDIF.
    You could modify the code slightly to get VAR1.

  • Monthly Averages

    MONTHLY AVERAGE SALES PRICE FOR THE LAST 12 MONTHS. EACH MONTH AVERAGE INCLUDED THE AVERAGE FOR THE WHOLE YEAR ENDING ON EACH MONTH.
    can any one help me

    Jerry
    Thanks for this. But I am having a bit of trouble following your lead. Perhaps I can tell you a bit more. I've got columns for each month (Jan, Feb, Mar, Apr). Are you suggesting I add a column after the last month? I have done this, but the problem is that while I can insert a formula in each item row of that column (giving me averages for all entries in the row), I seem to be unable to insert a formula in the category header row (Numbers won't seem to let me), as these cells are automatically meant to be the sum of the items below them. So, the category heading cells will sum the values (row averages) below them rather than giving me the average of the category headings for each month in their row. And of course, the sum of these averages is not necessarily the same as the average of the monthly sums. It seems to me I need a new table with a cell for each category row in the first table, but I am having trouble setting such a table up, i.e., creating formulas in one table to average category row cells in another. Any further ideas would be much appreciated.
    Sly

  • Functional module for 12 MONTHS AVERAGE SALARY

    hi all,
    I want to get the average salary for an employee for past 12 months from cluster tables. I believe the cluster table for that is PCL2? . I want to know the name of the function module to get the average salary for an employee for past 12 months from cluster tables. If anyone could explain me with help of the coding how to use that function module  - passing what all parameters, it would be great.
    I anyone have any custom report for extracting payroll data from cluster tables, Please let me know. Please share the coding. My e mail id is [email protected]

    Ribhu,
    You can retrieve the last payroll result for the year & read the YTD Gross (year-to-date) from the CRT table & divide by12 to get the Average Salary..
    ~Suresh

  • Monthly average at run time.

    Hi,
    My report contains,say 10 ,records for each month.can I get an average of a keyfig in that month when I run my query?
    Kind regards,
    Aru

    In the Key Figure properties under Calculate Single Value as option select "Average of all Values" or "Average of all values <> 0"
    See the documentation for this.
    http://help.sap.com/saphelp_nw04/helpdata/en/1f/25883ce5bd7b1de10000000a114084/content.htm

  • Formula Variables for Key Figure Rolling Averages 3/6 months

    Dear BEx guru! I need dynamic (user selectable range from select options) 3, 6 month averages for Sales, Inventory  Key Figures. I used variable offset alone and I am not getting the results.
    Mar/06 = 120 EACH, Apr/06 = 150 EACH and May/06 = 180 EACH, Jun/06 = 90 EACH, July/06 = 240
    User Calendar Month select options = Mar/06 to May/06
    Mar/06 (Avg) = (120150180)/3 = 150 EACH
    Apr/06 (Avg) = (15018090)/3 = 140 EACH
    May/06 (Avg) = (18090240)/3 = 170 EACH
    PLEASE SEND ME YOUR KIND RESPONSES! I APPRECIATE YOUR HELP!! write to [email protected]

    Hi,
    You may have to use the customer exit.  I am not sure whether there is any sap_exit variable available to provide such a calculation.
    Regards
    Sundar

  • Query to find out weekly average of job execution time

    I have a table which has the following details:
    CREATE TABLE JOB_DETAILS (JOB_START_DATE DATE,
    JOB_END_DATE DATE,
    JOB_START_TIME NUMBER,
    JOB_END_TIME NUMBER,
    HOURS_OF_EXECUTION NUMBER,
    DETAILS VARCHAR2(20));
    INSERT INTO JOB_DETAILS VALUES ('01-FEB-2007','01-FEB-2007',10.04,20.09,10.04,'WEEKDAY');
    INSERT INTO JOB_DETAILS VALUES ('07-FEB-2007','07-FEB-2007',00.00,00.00,00.00,'WEEKEND');
    commit;
    Job_Start_Date Job_End_Date Job_Start_Time Job_End_Time Hours_Of_Execution DETAILS
    1/2/2007 1/2/2007 10:04 20:09 10:04
    1/7/2007 1/7/2007 0:00 0:00 0:00 Weekend
    Our jobs wont run on week ends and on holidays where we see "Hours_of_execution" as 0.
    Week means Monday to Friday for me.
    (1) I want a query which gives me a weekly,monthly average of how many hours the job ran.
    (2) I want to find out the week, when the average execution of the job is &gt; 10 hours.
    can anyone help in framing this query to get the details?
    Thanks

    Why make it so hard for yourself by removing the time from the date and storing it separately?
    alter session set nls_date_format='DD/MM/YYYY HH24:MI:SS'
    session altered
    WITH t AS (SELECT SYSDATE start_date, SYSDATE+0.61 end_date FROM dual)
    SELECT start_date, end_date, numtodsinterval(end_date-start_date,'DAY') execution_time
    FROM t
    START_DATE          END_DATE          EXECUTION_TIME
    11/12/2008 11:22:21     12/12/2008 02:00:45     +00 14:38:24.000000

  • How can I find out my data usage for the past 3 months?

    Greetings all, I have been a long time Verizon customer, and as such I, along with my husband, was grandfathered into the unlimited data plan. When I last spoke to a representative, they informed me that the only way we were going to be able to keep our unlimited data was by paying the full retail price ($600+) to get a new phone. So we were considering upgrading and changing to one of the newer data plans so we could still get the discounted price on the new phone, but I would like to make sure I choose one with enough data, without paying for a bunch of data that I don't use, however MyVerizon only shows me the amount I have used since the start of the billing cycle. Is there a way to find out the data usage for both my husband and myself for the last 3 months so I can choose the right option?
    Thanks in advance for your help!

        Hello sweetpea1221! How exciting that you're considering upgrading with us. mrhelper is helpful, indeed. You can view your data usage for each line under the View Bill option via your My Verizon account. You can also view your 3 month average  data usage with our Account Analysis feature. Here's a link that will be helpful in doing so http://bit.ly/vnLjqO. I'm confident that we have a great plan to match your data needs. Please let us know if you have further questions.
    TanishaS1_VZW
    Follow us on Twitter @VZWSupport

  • Average Balances in General ledger.

    Hi All,
    The question may be silly and awkward - I am completely ignorant in GL
    Our requirement is to calculate the monthly average balances for each code combination id (GL_BALANCES) after the month end.
    One way is to calculate the average balance from daily balances.
    Just wanted to know if it is already getting stored in any table.
    Thanks in advance,
    jeneesh

    think there's no table storing the average daily balances as accounting is rather 'complex' - obey some standard. Say it, cash, unearned, accrued,..., and more.. that need special treatment... Suppose we can book the emplyoee salary today for salary paid next month..

  • Average Value

    Dear all,
    i have to calculate a query which contains the following data
                   ¦ Day 1 ¦ Day 2 ¦ ... ¦ Day 7 ¦ Avg. week ¦ Avg. month ¦ Avg. year ¦
    Value 1
    Value 2
    In Colum 1 to 7 the daily revenue should be displayed; in the column Avg. week i should show the daily average (sum of clumn 1 to 7 / 7). that's easy. but how should i calculate the monthly average or the yearly average ?
    i don't want to create 365 columns in the query to calculate just a average for the year? I tried with key figures with exeptionel aggregation (AVG) but that does not help. If i have daily data loads i have the same values in this key figure as in the others (of course).
    Any idea ?
    If preferred I could provide an Excel-File. Perhaps it is then easier to understand.
    Thanks,
    Marc

    Hi Marc,
    Create a structure:
    in first object  restrict revenue by calday and offset calday
    (a user entry variable)  by 6 ( ex if calday is 08/11/07 u will get revenue for  08/05/07)
    similarly do it 6 more time with offsets descending untill 1  and in the last object no offset which will give you the present day( as entered in the variable 0calday)
    now create a formula object  avg week ( sum of all above columns /7)
    now create another object for month(you can hide this if you want by hding it funder properties) : here restrict revenue by variable 0calmonth
    now create a formula object and use the above field value and calculate average using the available mathematical functions
    similarly do it for a year also (0fiscyear)
    Hope this helps
    Anand Raj

  • Average shown on line chart

    Post Author: jhogan
    CA Forum: Charts and Graphs
    I am trying to find a way to show the 13 month average as a line accross my line chart other than having to manually add a line.
    I have multiple charts that need to be created on a monthly basis and I would like to automate the production of the chart.
    Thanks,
    Jennifer

    Post Author: Dan3D
    CA Forum: Charts and Graphs
    If all else fails, this could be solved with the 3rd-party chart add-in I wrote (which has support for mapping print-time functions to a user-defined line). Moderator rules don't let mention it by name, but if you click on my profile, you'll find it.  See in particular macros @Y, @YSZ, @YSZN.

  • Strip alpha to take average

    I have a table that looks like:
    sub_dt date,
    cd    varchar2(5),
    day01 varchar2(5),
    day02 varchar2(5),
    day03 varchar2(5),
    day31 varchar2(5))
    sub_dt       cd       day01      day02      day03
    01-JAN-06  A10    e5           e4            e5
    04-FEB-06  A10    5             5              6
    It contains daily measurement values for the given cd. Sometimes the data is entered as an estimate, so it is stored with a preceeding e. Why I don't know. But what I need to do is create two different types of averages:
    1. The aveverage measurement by day - pretty easy avg(day01), avg(day02)...
    2. The monthly average for the cd.
    In either case I am stuck with these non-numeric values. What is the best approach for stripping out the alpha characters so that I can actually perform the math? I was thinking of using regular expresssion somehow, but I don't know if that is best. I was also thinking about creating a function to do a translate/replace of the alpha and return the number, but that is a whole lot of context switching - 31 times for each row.
    Second is that the average over the month is a bit tricky. I think that I am stuck adding the data together and dividing by 31 - (day01 + day02 + day03)/31, but I think that creates potential for incorrect results. Image if someone only inputs data for three days out of each week, then really they only should be divided by 12 and not 31. So after I convert the data to number I would need to evaluate the nulls...analytics maybe?
    I am guessing that I am making this more complicated than it really is and just need another pair of eyes to help me see forest through the trees.
    Thanks, Tony

    William -
    The ltrim or substr would be a good method if I knew that the only letter was "e". I wasn't very clear about that part. Since it is a varchar2 field and this application has no data integrity this field can have just about anything in it. Someone could enter e or x or any other combination of letters prior to the actual number.
    I like the collection idea, I will give that a shot.
    <b>Updated:</b>
    I used a combination of these two methods with really nice results.
    select sub_dt,cd,avg(regexp_replace(column_value,'[^0-9]+','')) month_avg
    from t, table(TableType(day01,day02,day03,....))
    group by sub_dt,cd;
    DT                  CD           MONTH_AVG
    08/02/2006 08:49:40 0056                 4
    08/03/2006 08:50:21 1001               145Thanks for the help, really great solutions.
    Tony
    Message was edited by: T

  • Crosstab YTD averages problem

    Pulling a large set of customer contacts (100,000s of rows) with each row being a contact. I have a crosstab which groups by location and employee, when the detail rows are the types of contacts (in person, telephone, etc) and then I have months across the top. Here's the problem I'm having:
    I need to calculate the average # of contacts per business day. I could countdistinct(contact_date) if I were basing the average on the number of days on which contacts occured (for each dept), but the report has to calculate averages for all departments based on the same # of business days per month (21 in January, 19 in February, etc.). If I just put the number of days on each row in the dataset, I could do min or max or avg and it would work fine for the months' averages, but the totals at the end for YTD won't work. I can't sum, because I have the # of business days on each row, so 1000 contacts in a month with 21 days would put a denominator of 21000.
    This is how it would look working the way I want it to.

    Thank Graham,
    when i use the same technique of setting up a nested counter and highlighting the fields based on that value...
    The counter should be set on every column of the row?
    It is because i found there is the problem, when i set the counter on every column...all the row will be highlighted without condition (x<=5), i think the counter may overcounted or not work.
    for example..
    user   action count
    1. a     10
    2. b     9
    3. c     8
    4. d     7
    5. e     6
    when i set the counter (let's say x<=2), on both user and action
    i will see the user 1,2 had been highlight and whole action column as well.
    and i also struggling with the filtering..
    i saw the whitepaper, can it apply in the crosstab?

  • Average Balances in GL-(Not a PL/SQL question - Related to Financials)

    Hi All,
    The question may be silly and awkward - I am completely ignorant in GL and tried a lot in Google..
    Our requirement is to calculate the monthly average balances for each code combination id (GL_BALANCES) after the month end.
    One way is to calculate the average balance from daily balances.
    Just wanted to know if it is already getting stored in any table.
    Thanks in advance,
    jeneesh
    Note: The question is already posted in Financial Services Forum.. ( Average Balances in General ledger. ). Sorry for duplicating.

    Hi,
    jeneesh wrote:
    ... Note: The question is already posted in Financial Services Forum.. ( Average Balances in General ledger. ). Sorry for duplicating.Since you know it's wrong to post the same question twice, and you know where the correct forum is, don't the question here. Close this thread right away.

Maybe you are looking for

  • How many devices can i use with the time capsule?

    When I said devices, I mean iphone, ipad, macbook and imac

  • All Numbers documents open when booting Numbers

    I may come off ignorant asking this, but when I open Numbers on my MBA it also opens all my numbers documents so if I only want to work on one document I have to manualy close the others. As of now I only have 3 documents created so it's not a big de

  • Authorisation Restrictions in PR05

    Hi Experts, We want to restrict Authorisatons in t-code PR05 userwise ie., The scenario is  X user will created the Trvl Exp. in PR05  Head-HR ( Y user) will approve the Trip ( only display) Pre-Audit(Z User) will  Verify the Expense Voucher and Trip

  • Working out sample BPM's

    Hi there, maybe not strictly a logic question but.... i was wondering if anyone new an easy way of working out the BPM of a sampled loop, vocal etc. Sorry if this is a stupid question!! Cheers Alex

  • SAP Archive process

    Hi all, How to archive the data from SAP when the data have a delete tag? can any one please explain the archive process in SAP? we have to delete production order data? Thanks in advance. Regards, veera Edited by: Veerab on Oct 3, 2011 9:52 AM