Averaging an Average

I'm trying to average an average and I'm running into a bit of trouble. I want to determine a daily average of sales and then average the daily averages. So, if I have 3 sales for Day 1 ($5, $10 and $15, average sale being $10) and 4 sales for Day 2 ($1, $2, $3 and $4, average sale being $2.50), I want to average those together. Total Sales (Avg: $10 and $2.50).
I made some progress, by using the PARTION BY function, but the problem is that I can't run an average...
SELECT a.month, a.sales, AVG(a.sales) OVER(PARTITION BY a.day ) AS Daily_Sales
FROM schema.profits a
But now I want to be able to Average that Daily_Sales calculation and then group by the month to get my final result. However, when I try to add in average to the daily_sales, I get "ORA-30483: window functions are not allowed here". Any ideas?
Thanks,
Jeff C.

A slightly better version
SQL>set sqlblanklines on
SQL>set numformat 99.99
SQL>
SQL>WITH DATA AS (
  2  SELECT 5 sales,trunc(SYSDATE-4) da FROM dual UNION ALL
  3  SELECT 10 sales,trunc(SYSDATE-4) FROM dual UNION ALL
  4  SELECT 15 sales,trunc(SYSDATE-4) FROM dual UNION ALL
  5 
  6  SELECT 1 sales,trunc(SYSDATE-3) da FROM dual UNION ALL
  7  SELECT 2 sales,trunc(SYSDATE-3) FROM dual UNION ALL
  8  SELECT 3 sales,trunc(SYSDATE-3) FROM dual UNION ALL
  9  SELECT 4 sales,trunc(SYSDATE-3) FROM dual UNION ALL
10 
11  SELECT 1 sales,trunc(SYSDATE-2) da FROM dual UNION ALL
12  SELECT 2 sales,trunc(SYSDATE-2) FROM dual UNION ALL
13  SELECT 3 sales,trunc(SYSDATE-2) FROM dual UNION ALL
14  SELECT 4 sales,trunc(SYSDATE-2) FROM dual UNION ALL
15 
16  SELECT 5 sales,trunc(SYSDATE+1) da FROM dual UNION ALL
17  SELECT 10 sales,trunc(SYSDATE+1) FROM dual UNION ALL
18 
19  SELECT 15 sales,trunc(SYSDATE+2) FROM dual UNION ALL
20  SELECT 1 sales,trunc(SYSDATE+2) da FROM dual UNION ALL
21  SELECT 2 sales,trunc(SYSDATE+2) FROM dual UNION ALL
22  SELECT 3 sales,trunc(SYSDATE+2) FROM dual UNION ALL
23  SELECT 4 sales,trunc(SYSDATE+2) FROM dual
24  )
25  select trunc(da), avg(sales) daily_avg, avg(avg(sales)) over () avg_of_daily_avg
26  from data
27  group by trunc(da)
28  order by 1;
TRUNC(DA) DAILY_AVG AVG_OF_DAILY_AVG
21-MAY-10     10.00             5.50
22-MAY-10      2.50             5.50
23-MAY-10      2.50             5.50
26-MAY-10      7.50             5.50
27-MAY-10      5.00             5.50

Similar Messages

  • Moving average price (average price)

    Dear All,
    Is there any standard report in SAP to have moving average price (average price) for single material and for specific period?
    Please let me know the details.
    Amit

    Go to MB5B report give the period you want
    and calculate MAP manually from fields Total value and Total Stock.
    Regards
    Krishna Mohan

  • Why does the system need two average costs - 'Average' and 'Average Rates'?

    Hello Gurus!
    The documentation does give definitions for 'Average' and 'Average Rates' cost types, but at a very basic level.
    http://docs.oracle.com/cd/A60725_05/html/comnls/us/cst/settask.htm
    I would like to know why the system needs two costs? How are they calculated and how are they used?
    Thanks!

    Hello,
    I can suggest you a workaround that will help you keep only the 64-bit version of Photoshop.
    Visit "Uninstall a Program" in Windows 7 Control Panel and uninstall Photoshop completely.
    Visit this page and download trial version of Photoshop.
    Run the installer manually and choose the 64-bit version only (uncheck 32-bit version).
    Launch the product and specify your Adobe ID credentials.
    The product will switch to non-trial (i.e. full) mode when it recognizes your Adobe ID.
    Regards,
    Amit Batra
    Engineering Manager,
    Amit Batra

  • Average of Averages before aggregation

    HI,
    I have an issue calculating the averages of a score in the query, we are on BI 7.
    Here is the example
    Emp ID............Q1 Score.....Q2 Score..... Average of Q1&Q2
    12345............. 66.67 .........100...............83.34
    24689............. 66.67..........75................ 70.83
    98765............. 33.33...........  -   .............33.33 (As there is no value uner Q2score the average is done by 1 insted of 2)
    Total.............166.67........ 175............. 187.5
    Average....... 166.67/3 .... 175/2 ........... 187.5/3
                          55.56 .........87.5 ................ 62.49 (This value is derived from Average of Q1&Q2)
    when i try to get the value 62.49 directly with out displaying Employe id's (by putting employee id under structure under Row)
    This is how the query calculatin with employee under structure
    Emp ID............Q1 Score.....Q2 Score..... Average of Q1&Q2
    EMPID .............55.56 .........87.5 ............ (55.56 +87.5)/2 = 71.53
    i am getting different value which is the average of (55.56 +87.5)/2 = 71.53 which is not the correct value
    I have used exception aggretion and still not able to find correctanswer.
    Can any one please let me know if there is  any workaroud
    Thanks,
    Kumar.

    Hi Kumar:
    Please refer to the documentation below.
    Section on "Formula Collision", Slides 37 and 38 of the document "BW OLAP Aggregation".
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d61b1e95-0501-0010-dfbe-a03970712ef1?QuickLink=index&overridelayout=true
    Pages 7 and 8 of the document "Selection/Formula Properties: Enhancements"
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c08b9190-0201-0010-5d8e-f9cee963f0da?QuickLink=index&overridelayout=true
    Regards,
    Francisco Milán.

  • Overall Average and Average of part of data-set displayed simultaneously

    I am trying to write a report on Discoverer 10.1.2 that will display the average for a sub-set of a data population alongside the overall average of the whole population, BUT NOT display the average for the remaining sub-sets.
    For example:
    If there are 5 regions, A, B, C, D & E, the requirement is to display the average for region A against the overall average (averaged across all regions) and not to display the averages for teams B, C, D & E.
    Can anyone suggest how this could be achieved in Discoverer Desktop/Plus/Admin?
    Thanks
    Duncan

    Hi James,
    It looks to me like your code is not giving you the results you desire because of an assignment syntax error.  You want to add all the Upr_Values together and then divide by the Upr_Count to get the overall average for the upper lobe.  Your code, though, just overwrites the previous Upr_Value with the current one and assigns the value +1 to Upr_Count each time:
    Upr_Value =+ Chd(iLoop, "Strg_Angle")
    Upr_Count =+ 1
    Here's what you need instead to calculate the overall average:
    Upr_Value = Upr_Value + Chd(iLoop, "Strg_Angle")
    Upr_Count = Upr_Count + 1
    If you want to get the average values for each X value below the blue line, then I recommend using the Calculate() command to create two new sets of X and Y channels, one set for the upper lobe and another set for the lower lobe.  The Calculate() command can also set all unwanted data to 0 or Null so that you can then calculate the per-X value average in each lobe with the linear approximation function.
    If you want help with this, post or email me a sample data set,
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments
    [email protected]

  • How can I create a view of top five teams averages based on individual averages of that team?

    I have created a list that groups teams by their Team name (Team column) with the individuals members (participants column) averages and their team average (total average view option).  I want to only display the top five teams that have the overall
    top team averages.  I have a list that contains a team name, average minutes, week, and participant. The team manager plugs in each week a new entry for each participant on the team.  I have a view that computes each team average but I want a view
    of the top five teams based on the top averages of the team (not individual participant average).  Unfortunately, I can only seem to get all teams grouped with individuals of that team, their individual averages and the team average but can't figure out
    only how to show the top five teams top average.  Because it's a total (team average) and not a separate column, I can't get a view by team based on total average.  I can by top individual average but not by the team.  Can some one help me figure
    out a solution?

    A calculated column won't work because a calculated column can only reference the individual item, not the entire list or a subset.
    You could do javascript to build this, but to me it's easier to just use Excel.
    Andy Wessendorf | Solution Foundry [email protected]

  • In OBIEE Report Grand Total instead of Average(Average)  use Sum(Avg)?

    Hi All,
    In OBIEE Report Grand Total average always shows Average of average (Default) "avg(avg)" , can i overwrite this functionality to sum of average "sum(avg)".
    Thanks in advance
    Regards
    Kandasamy

    Hello,
    You can try the following:
    Remove the calculate result as setting for the three KFs.
    In exception aggregation set property to average with ref char as leave start date.
    Check if it works.
    If the above dosent work, set reference char to emplyee ID and check.
    Either one of them has to work
    REgards,
    Shashank
    Edited by: Shashank Dighe on Apr 2, 2009 9:03 AM

  • Having issue with a Sum/Average program

    The issue I get when I run the command is, let's say I enter 4 numbers, 5, 7, 9, 16 then enter a 0 to end the count, the avg it gives me is 8.0 instead of the 9.25 it should be. Any insight would be greatly appreciated.
    import java.util.Scanner;
    public class StephenVanoverSumAverage
        public static void main(String[] args)
              Scanner keyboard = new Scanner(System.in);
            double count = 0.0;      
            double sum = 0.0;   
              double num;
            System.out.println("Enter a number (Type 0 to quit): ");
              num = keyboard.nextInt();
            while ( num !=0 )
                   System.out.println("Enter a number (Type 0 to quit): ");
                   num = keyboard.nextInt();
                sum += num;
                count++;
            double average = sum / count;
            System.out.printf("Average is " + average);
    }

    Not quite, since the first number is discarded. The zero is included in the sum, but the first number entered is not. The count is incremented for the zero, true, but I think that is not the problem.
    Still, the code could be cleaner with respect to both when the count is incremented, and what numbers are included in the sum.
    {?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Function to replace division by zero error cells with blank cells when calculating a numeric average

    Hi everyone,
    I have a five sheet spreadsheet that uses data from four sheets to calculate numeric averages in the fifth. The problem is that there is not always data in all four sheets which produces a division by zero error in the averages sheet. Is there a function or setting in Numbers 2.3 (not yet ready to upgrade to Numbers 3) that will allow these division by zero cells to be replaced by blank cells.
    I have tried using statements of the form =AVERAGE(IFERROR(Sheet 1::Table 1:: B4,""),IFERROR(Sheet 2:: Table 1:: B4,""),Sheet 3:: Table 1:: B4,""), Sheet 4:: Table 1:: B4,"")). however instead of a division by zero error this produces an error telling me "the function AVERAGE expects that a number, date or duration but found "." ". It looks as though I will have to make about 400 changes to my sheet as these errors are in this and approximately 100 other cells!
    I am hoping that there is some way if possible of correcting these errors without having to manually edit each cell individually.
    Thanks,
    Hugh

    Hugh,
    You may want to consider an intermediate sheet to handle the errors and then pass the result on to the main sheet.
    In the following mockup, I've created a small interposing table the consists of a list of sources in column A and the result from each table. In the example, I perform some operation on those intermediate results, to be passed on to the main table. This may not be a good example, and since I don't know the overall goal of your project it's just a surrogate. (In real life we probably wouldn't be interested in finding the average of averages.)
    The expression in Summary::B2 is:
    =IFERROR(INDIRECT(A&"::B4"), "SourceError")
    Regards,
    Jerry

  • Using average days between dates to predict a launch date on another produc

    I hope someone might be able to help me out here.
    I am at the limit of my Webi expertise! (which is not saying a lot)
    We have a universe containing date information relating to the launch of products thus:
    Product Name
    Supplier Name
    Category
    Sample Availability Date
    Testing Start Date
    Launch Go Date
    It is a simple matter to create a variable u2018Project Timeu2019 as DaysBetween(Testing Start Date;Launch Go Date)
    And using the Average function we can create Average Project Length - Also with the Report, and Section keywords we can show the global average, and averages by Supplier and Category.
    Here is my problem.
    We also have Products in the universe that have yet to have their projects kicked off, so Testing Start Date and Launch Go Date for those products are null data. I want to use the Sample Availability Date and the Average Project Length variable to predict the probable Launch Go date, however, in the report this element shows up as an empty cell.
    Does anyone have an idea how I might achieve this?
    Many Thanks
    Mark

    OK...
    Lets imagine there are records for 100 devices in the universe.  75 of them have valid project start dates and launch dates.  25 of them have neither because those projects are yet to start.  However they do have a sample availability date.
    Using the DaysBetween function I can create a variable called project length from the start and launch dates.  I can then use the Average function to get the average project length (for the devices that actually have a project length)
    Somehow I want to add this average project length to the sample availability date on the records that have yet to have a start date.
    As projects end they will add to the average, and we can see how close they were to the predicted launch. As new records are added they will automatically have a predicted date.
    Right now I have the average project length, If I create a table filtering on completed projects (Projects with a non-null launch date) and I add a column showing average project length, because I've used the In Report keyword on the average, it shows the average value in this table.
    If I have a stand-alone cell with the average project length it shows the right value
    But if I have a table showing the devices yet to start (filtering on Null start date) If I add the average project length into that table it shows as blank (I.e. no value at all)
    Hope this helps

  • SSM - Doing a Weighted Average in Time Series Consolidation

    Hi,
    We have a requirement wherein the Yearly/ YTD View of a scorecard has to be a weighted average of the Quarterly Values.
    Please let me know if there is any way to implement this while doing a time series consolidation.
    Thanks,
    Peeyush

    Hi Peeyush,
    You can use the following standard methods for time consolidation:
    SUM,
    FIRST DATA VALUE,
    LAST DATA VALUE,
    INCLUSIVE AVERAGE,
    EXCLUSIVE AVERAGE,
    WEIGHTED ON ANOTHER MEASURE
    The command in IDQL to set the time consolidation for a measure  to WEIGHTED is the FOLLOWING:
    SET VAR kpi1 WEIGHTED kpi2
    You can also use the Measure Properties dialog box (in the tab 'Numeric') to set this property. You may need to first issue the command SET SHORT in IDQL in order to correctly choose a variable selected from the dropdown list.
    If the measure kpi1 is monthly, for example, then the quarterly and yearly values will now display as weighted average with kpi2.
    Hope this helps!
    Best regards!
    Ricardo

  • By default in BPC values are sum in node level, It does not make sense to sum averages on parent nodes.

    HI Guys
    we have an business requirement to store data in average figures ,
    The values  are entered on the base member level but in reports we need to show average values  on the parents level instead of sum
    ( by default in BPC values are sum in node level),it does not make sense to sum averages on parent nodes.
    we managed it with excel formulas ,but we r facing the problem with dimensions which are in context.
    (i tried using dim memeber formulas but AVG key word is not accepting the system in member formulas)
    at last by using formula we managed the report but im worried abt that if there is no formulas ,how we will manage
    pls suggest any solution to show average values on the node level in specific reports

    Hi Krao,
    Please define what do you mean by average - arithmetic average or weighted average (has more business sense to my mind).
    Also, please provide some samples, explaining dimensions used in average calculation.
    In our case we use dimension member formulas to show average prices, discounts etc. in the reports.
    B.R. Vadim

  • Average computed incorrectly ?

    Hello ,
    please help me with the following problem.
    while using OBIEE 11g (11.1.1.5.0) I came into a situation when average is not computed correctly.
    essentially it happens when creating a simple analysis having a single view that has one or more EXCLUDED columns (not using all attributes from the analysis)
    in that case it seems that OBIEE :
    1. computes first an average per ALL attributes of that analysis (even those not included in the view)
    2. the results produced at step 1 are further aggregated to deliver results for the view. so an average of average is computed, producing wrong results (from the analysis view point of view).
    I've created a simple test case, using 2 tables TEST_DIM_1 (as a dimension table ) and TEST_FACT (as fact ). the BM is almost a copy of physical layer; MEASURE1_AVG is defined on MEASURE1 column, having AVG as aggregation rule.
    the analyses is using ATTRIBUTE_1_1, ATTRIBUTE_1_2, MEASURE1_AVG . in the view , ATTRIBUTE_1_2 attribute is EXCLUDED from the view.
    as a result, the MEASURE1_AVG is computed incorrectly.
    needless to say, if ATTRIBUTE_1_2 is completely removed from analysis (not only excluded from the view), the average is correct.
    incorrect result in the analysis :
    ATTRIBUTE_1_1          MEASURE1_AVG
    AMER                     600.00           
    EU                1003.33      
    correct avg per ATTRIBUTE_1_1 :
    ATTRIBUTE_1_1          (CORRECT AVG PER ATTRIBUTE_1_1)
    AMER                (600.00)      
    EU           (671.67)
    table definitions and values below :
    create table TEST_DIM_1
    ID NUMBER(20) not null,
    ATTRIBUTE_1_1 VARCHAR2(10),
    ATTRIBUTE_1_2 VARCHAR2(10)
    alter table TEST_DIM_1
    add constraint TEST_DIM_1_PK primary key (ID);
    create table TEST_FACT
    ID NUMBER(20) not null,
    MEASURE1 NUMBER,
    MEASURE2 NUMBER,
    TEST_DIM_ID NUMBER(20),
    F_ATTRIBUTE VARCHAR2(100)
    alter table TEST_FACT
    add constraint TEST_FACT_PK primary key (ID);
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (1, 'EU', 'RO');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (2, 'EU', 'BG');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (3, 'EU', 'DE');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (11, 'AMER', 'US');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (12, 'AMER', 'MX');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (4, 'EU', 'RO');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (5, 'EU', 'RO');
    insert into TEST_DIM_1 (ID, ATTRIBUTE_1_1, ATTRIBUTE_1_2)
    values (6, 'EU', 'DE');
    commit;
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (1, 10, 10, 1, 'SMALL');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (2, 10, 10, 4, 'SMALL');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (3, 10, 10, 5, 'SMALL');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (4, 2000, 2000, 2, 'BIG');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (5, 1000, 1000, 3, 'BIG');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (6, 1000, 1000, 6, 'BIG');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (11, 500, 500, 11, 'MM');
    insert into TEST_FACT (ID, MEASURE1, MEASURE2, TEST_DIM_ID, F_ATTRIBUTE)
    values (12, 700, 700, 12, 'MM');
    commit;
    alter table TEST_FACT
    add constraint TEST_FACT_DIM1_FK foreign key (TEST_DIM_ID)
    references TEST_DIM_1 (ID);

    Here's my solution:
    I had to set the binding for the dropdowns to numbers. I didn't know what numbers you were using, so I picked "0" for what "N/A" would get, but you can pick whatever. For the form, I made one dropdown and then copy/pasted it however many times I wanted. (In this case 8 to match your example.) I put the code in the calculate event for the text field I was using to report the average.
    var n = 0;
    var total = 0;
    for (var i=0; i<8; i++){
              if (!xfa.resolveNode("dd1["+i+"]").isNull && xfa.resolveNode("dd1["+i+"]").rawValue != 0){
                        n++;
                        total += Number(xfa.resolveNode("dd1["+i+"]").rawValue);
    this.rawValue = total/n;

  • How to calculate averages and send to a file?(source code)

    Having trouble the book isn't very clear on how to use averages.............could some give me an example of a program..................that gets averages and send to a file..........?

    From Deitel and Deitels monster 'How to Program' :
    import javax.swing.JOptionPane;
    public class Average {
    public static void main ( String args[] )
    int total, gradeCounter, gradeValue, average;
    Swing grade;
    total = 0;
    gradeCounter = 1;
    while ( gradeCounter <= 10 ) {      //assuming 10 values
    grade = JOption.showInputDialog ( "Enter grade: " ) ;
    gradeValue = Integer.parseInt ( grade );
    total += gradeValue;
    gradeCounter = gradeCounter + 1;
    average = total / 10;
    JOptionPane.showMessageDialog (
    null, "Class Average is" + average, "Class Average",
    JOptionPane.INFORMATIOIN_MESSAGE );
    System.exit ( 0 );
    Import package java.io
    Three stream objects are created when you execute , System.in, System.out, System.err
    System.out can be directed to send it's output to a file or disk.

  • Time Dimension Average @ Lev2

    Hi,I'm having a problem with calculating the TB Average at Lev2 of my Time Dim.Time Dim: Week (Lev0), Month (Lev1), Year (Lev2), Time (Lev3)Week to Month OkMonth to Year Not OkMonth to Year calculates the average using the Month TB Average (average of average).I've tried using a Member calc [@AVG (SKIPBOTH,@LEVMBRS ("Time",0))] for the Year Member so it calculates the average based on the Lev0 figures.Don't really want to have a separate the Years into a different dimension.Thanks in advance.Mark

    Thanks for your reply. Did you use the dimension wizard of OWB to create pure relational dimensions (Not owb/oracle dimensional structures) ?
    How did you work out week, financial years pieces upon using this OWB dimension wizard?
    Thanks for your help.

Maybe you are looking for

  • Whole workgroup (SMB) dies for Macs but not PCs

    Hello all, I'm having a very frustrating problem with a mixed Mac (Snow Leopard, all latest updates) and PC (Vista/XP) home network. Normally everything works fine and I can share files and printers between the Macs and PCs (i.e. this is not a simple

  • Handling socket exception - Retrying a "try" block

    I have a program which attempts to retrieve an object through a socket. However sometimes I get the following exception: java.net.SocketException: Connection reset This is a problem as I need the object to continue program execution. An overview of t

  • Shared photos/videos not appearing in streams on originating imac, only icloud icon

    I share pictures and photos to icloud from Aperture 3.5.1. The photos and videos are available on other devices that share the same icloud stream, but in Aperture on the originating imac, when I look in the "icloud" section at the photo streams, I se

  • Commas in text fields...

    I have a couple fields where people enter some numbers and then calculations are done (behind the scenes), and a resulting number appears in a new field. I need to know how to get commas to appear in the appropriate places (for instance - if someone'

  • I used to love my AppleTV, now I hate it :(

    This new update is horrible! I have had my AppleTV since August and had zero problems with it until the new update. In the past week I've updated the AppleTV, my iPhone 4s, and the Remote app and now nothing works like it should. Homesharing has been