MDX - How to group results to calculate the average

Hi,
I have the following MDX query which selects total unique visits per day between a range of my choosing:
WITH MEMBER [Measures].[MyAvg] AS
Round( AVG(
EXCEPT([Dim Date].[Day Of Week].Members,
{[Dim Date].[Day Of Week].[All].&[1],[Dim Date].[Day Of Week].[All].&[7],[Dim Date].[Day Of Week].[All].UNKNOWNMEMBER}
), [Measures].[UniqueVisitsDay]
), 2)
SELECT { [Measures].[MyAvg] } ON COLUMNS,
NON EMPTY { [Dim Date].[Year Month Date].[PK Date].&[2013-03-01T00:00:00]:[Dim Date].[Year Month Date].[PK Date].&[2013-03-31T00:00:00] } ON ROWS
FROM
[MyCube];
Which gives me the following results:
01/03/2013 634
02/03/2013 16
03/03/2013 19
04/03/2013 698
05/03/2013 704
06/03/2013 692
07/03/2013 774
08/03/2013 755
09/03/2013 9399
10/03/2013 19990
11/03/2013 775
12/03/2013 835
13/03/2013 868
14/03/2013 900
15/03/2013 844
17/03/2013 19
18/03/2013 248
19/03/2013 920
20/03/2013 958
21/03/2013 1092
22/03/2013 798
23/03/2013 21
24/03/2013 10
25/03/2013 731
26/03/2013 770
27/03/2013 537
28/03/2013 300
29/03/2013 28
30/03/2013 8
31/03/2013 4
What I need to do is get the average of this set of results over the month.  I am expecting this answer:
1478.233333 (which is total unique hits - 44347 / total rows - 30)
But when I change my MDX code to this:
WITH MEMBER [Measures].[MyAvg] AS
Round( AVG(
EXCEPT([Dim Date].[Day Of Week].Members,
{[Dim Date].[Day Of Week].[All].&[1],[Dim Date].[Day Of Week].[All].&[7],[Dim Date].[Day Of Week].[All].UNKNOWNMEMBER}
), [Measures].[UniqueVisitsDay]
), 2)
SELECT { [Measures].[MyAvg] } ON COLUMNS,
NON EMPTY { [Dim Date].[Year Month].[Mar 2013]:[Dim Date].[Year Month].[Mar 2013] } ON ROWS
FROM
[MyCube];
I get the following result:
MyAvg
Mar 2013 9868
Actual: 9868  
Expected: 1478.233333
What am I doing wrong?
Thanks,
Rob

Hi Rob,
In SQL Server Analysis Serviceswe do not have a measure Average aggregation type. Fortunately, we have Sum and Count, and since Average = Sum / Count, we can build our own Average aggregation when we need one. Here is a blog about how to create a average
measure, please refer to the link below.
Average Aggregation in Analysis Services
Regards,
Charlie Liao
TechNet Community Support

Similar Messages

  • How do calculate the average of a group of percentages excluding percentages listed as zero on Numbers?

    Hey all
    This is driving me crazy!
    I need to calculate the average of a group of percentages excluding cells listed as '0%'.
    Please see screen print below, numbers highlighted need to be averaged, when the table is filled out correctly some will remain '0%' whilst others will have a value, I want the average to be calculated only using numbers with a value greater than '0'.
    FYI I am looking for the result to display in 'X2'
    Thanks :-)

    you can use the averageif() function. Here is a simple example to get you started:
    In this example the average if() function averages values that are non-zero
    C2=AVERAGEIF(A1:E1,"<>0",A1:E1)
    this is shorthand for select cell C2, then type (or copy and paste from here) the formula:
    =AVERAGEIF(A1:E1,"<>0",A1:E1)

  • How do I calculate the average of ONLY the populated fields?

    I'm working on an Adobe form to streamline the process of summarizing course evaluations.  To protect the anonymity of the students, instructors with 10 or fewer students are given a typed summary of the evaluation results.  On the first half of the evaluation, the students are asked to rate a series of statements from 1-5.  Three of these are highlighted on the summary form with the average response. 
    I've already set up the form with 10 unique boxes for each question and an 11th box which calculates the average.  Each field is named according to the question number and the student's "number" (I arbitrarily gave each student a number so that each field would be unique):
    i.e. #1. Questionquestionquestion.  Q1S1  Q1S2  Q1S3  Q1S4  Q1S5  Q1S6  Q1S7  Q1S8  Q1S9  Q1S10  1AVG
    The problem, of course, is that no matter how many students were actually in the class, the AVG field will always be calculated based on a group of 10...which isn't accurate or fair to the instructor.  I thought about just changing the form and removing the unused fields from the equation each time I make up a new summary, but the point of creating a form was to make it as quick and easy as possible to bang these things out... Plus, some of my coworkers might be using the form from time to time and I'd have to explain what they have to do and if they don't have Adobe Acrobat then they can't actually make the changes and blah blah blah...it just gets ridiculous really quickly!
    So anyway, I tried reading some other posts for similar questions in an attempt to figure out a custom calculation script for myself, but I just couldn't focus on it.
    I was hoping someone could explain how to write a custom calculation script that will omit any fields which are left blank... Or, even better...is anyone willing to write it for me?  At least just an example of the first guy, cause I could probably figure out how to get all the other ones from there.
    Thanks.

    In formcalc the function Avg will calculate the average of only the fields with a value in them. So you would would put in the calcuate event of the average field:
    $ = Avg(Q1S1,Q1S2,Q1S3,Q1S4, etc)

  • How to calculate the average inventory in ABAP

    Dear All,
    Please find the below formula and this formula how to calculate the Average inventory at value.Please let me know the abap base tables and the corresponding fields.
    Formula
    Inventory Turnover = Cost of Goods Sold (COGS) / Average Inventory at value.
    Thanks
    Regards,
    Sai

    Hi Arivazhagan,
    Thanks for your quick response .
    The field MBEWH from the table is fulfill the average inventory at value.
    For Eg :I want to calculate Inventory Turnover = Cost of Goods Sold (COGS)/
    Average Inventory at value.
    so shall i take Inventory Turnover = Cost of Goods Sold (COGS)/MBEWH
    The above formula will meet my requirement to find the average inventory Turnover.
    Thanks
    Regards,
    Sai

  • How do i calculate the average of runs that have variable number of samples?

    Hi
    I am trying to calculate the average trajectory from  lets say 4 runs, with varying sample size.
    That is, if the the 4 runs have 78,74,73,55 samples respectively, How do I calculate the average of (78+74+73+55)/4 , (78+74+73)/3 and (78+74)/2  and 78/1 ?
    Thank you

    I'm not sure you gave a sufficient information. Assuming that you just want to calculate a linear average of the data collected in consecutive runs, you have two simple methods :
    1/ concatenate the data before calculating the mean.
    Simple, but can occupy a huhe amount of space since all the data have to be stored in memory
    2/ store only the means Mi and the corresponding number of data points ni and calculate a balanced mean : M = sum (ni x Mi) / sum (ni) )
    The attached vi illustrate both methods.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Averages.vi ‏40 KB

  • Calculate the average value

    the data I measured changed rapidly, so i want get the average value of the data
    Do not tell me to use mean.vi , i have already know that.
    and i got an idea which is add the data into an array every time, then sum of all the data value and take the result divide by the number of elements
    but i dont know how to achieve that, anyone can build a simple vi to show me ? thank you
    i have attached my vi which is using mean.vi to calc the average value, you can delete it and using in your way ,  thank you !
    Solved!
    Go to Solution.
    Attachments:
    EN-new.vi ‏274 KB

    Hi I got a similar issue for averaging. I used the mean.vi from the math function but the average is rolling when i run it. I am trying to calculate the average for the data i read to the RT FIFO (which is around 40000 lines).I got the writing part working, however, when i am reading the data, I couldn't get it working. I thought i read the data as a 1-D array, and then pass it to the Mean.vi and then got the result. But seems like the mean is only showing the last data in the array.
    Can someone help me with this??
    Attachments:
    FPGA-vi.png ‏242 KB
    RT-vi.png ‏182 KB
    RT-2mod.vi ‏515 KB

  • Javascript to Calculate the Average of a column

    I have a column of fields in my PDF that I am trying to calculate the average for.
    My problem is that there are 7 fields, but all 7 may not be filled in so I think I need some kind of "if" statement that would only count the number of fields that have values.  Then somehow work that into the rest of my calculation...
    This is what I have so far...
    (function () {
        // Get all of the field values, as numbers
        var v1 = +getField("column.0").value;
        var v2 = +getField("column.1").value;
        var v3 = +getField("column.2").value;
        var v4 = +getField("column.3").value;
        var v5 = +getField("column.4").value;
        var v6 = +getField("column.5").value;
        var v7 = +getField("column.6").value;
        var v8 = +getField("column.7").value;
        // Calculate the result and set this field value
        event.value = (v1 + v2 + v3 + v4 + v5 + v6 + v7) / the number of fields that were filled in;
    I'm pretty new to javascript. Any help would be greatly appreciated! THANKS

    First, I woul write this function withou field references to make it more universial, and then I would make it a document level funcion so it could be used more than once in a PDF and easily brought into another PDF.
    function Avg() {
    // computer average of non-empty passed field names
    var sum = 0; // sum of fields
    var count = 0; // counter for non-blank fields
    for(i = 0; i < arguments.length; i++) {
    var iField = arguments[i]; // get the i element from passed arguments
    var fField = this.getField(arguments[i]).value;
    if(!(isNaN(fField)) ) {
    // field is a number
    if(fField.toString() != '') {
    // field is not null or blank
    sum += Number(fField); // add to sum
    count++; // increment count
    } // end not blank
    } // end number
    } // end loop through arguments
    if(count != 0) {
    // compute average if there is one or more items to average
    return sum / count; // return average
    } else {
    return '';
    } // end no average computed
    } // end Avg function
    Your custom calculation script then becomes:
    event.value = Avg('column.0', 'column.1', 'column.2', 'column.3', 'column.4', 'column.5', 'column.6', 'column.7');

  • Calculate the average with respect to time (moving average)

    hello,
    I am desinging a prototype to detect a kind of cardiac illnesses. I am obtaining beats per minute of heart. At the one of stages of project, I want to calculate the running or moving average of beats per minute at every last 10 seconds. For example, the measurement can continue for 10 minutes, but prototype must calculate the average of beats per minute for last 10 seconds. The time interval must be dynamic (as latest) and adjustable. Additionally, I can adjust the time interval, for example last 10 seconds or last 25 seconds. I will be completely grateful for your helps, thank you
    Attachments:
    heart beat final.vi ‏338 KB

    You might want to look at the Mean PtByPt VI.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Help..! ..how to calculate the average interest rate in discoverer?

    help..!
    I want to calculate average interest rate in discoverer, question describes below:
    1. the data have 4 columns, 1 account number, 2 balance, 3.interest rate, 4. product type 1, product type 2
    2.average interest rate =
    sum (product type1 account bal * rate / sum(product bal)).
    a*sum(product bal) is sum every records column 2 according the type of product
    b*every record need to calculate using balance to divide sum(product bal) for calculate the rate of the sum(product bal) of type of product
    c* sum(b*) is what my answer rate.
    3.
    I need to display average interest rate in discoverer, and each product have a one average rate according user drill-up or drill-down product dimension.
    *product dimension have two level
    please tell me how to let every record divide by group sum(product bal)
    or tell me how to solve this problem.
    thanks!
    david

    Hi David
    Try using the AVG analytic function.
    Best wishes
    Michael

  • How can i calculate the average in java

    how can i calculate the avergae mark out of two marks for instance in like exam mark out
    of two other ones
    thanks for considering this message

    Average or Mean:
    sum_of_N/N
    Here N is the number of marks.
    sum_of_N is the total sum of n(all marks added together)
    public int average(int[] marks) {
    int sum;
    sum = 0;
    for(int i=0;i < marks.length;i++) {
    sum=marks[i]+sum; // keep adding to the total
    return average = sum/marks.length;
    // warning- using an int here can be a pitfall(we could have a decimal outcome).
    }

  • How I manually calculate the Average Valuated Stock Value like in MC.3

    In the R/3 transaction MC.3  the  "Average Valuated Stock Value" help window shows a formula to calculate it.
    AVSV = ( begining stock value + n stock value at months end ) / ( n + 1 )
    What is the meaning of the N?. Where is this value come from.?
    I'd really appreciate any help.

    Hi
    N is the number of periods. The calculation with an example is as follows:
    Op. Stock Value on 1.12.2006: 40
    Cl. Stock Value on 31.12.2006: 80
    Op. Stock Value on 1.1.2007: 80
    Cl. Stock Value on 31.1.2007: 120
    The above can be viewed in MB5B
    In MC.3, if you choose the period 12.2006 to 01.2007, the calculations are as follows:
    AVSV for 12.2006: {40+(1*80)}/2 = 60  [N = 1 period]
    AVSV for 01.2007: {80+(1*120)}/2 = 100  [N = 1 Period]
    Total AVSV for 12.2006 to 01.2007: {40+(2*120)}/3 = 93.33 [N = 2 Periods]
    Hope this clarifies.
    Thanks

  • Calculate the average value of 10000 samples stored in a file. LVM with LabView

    Hello, I'm using a NI 6034 to acquire through _ LabView a signal in volts from a pressure transducer, these data then save them to a file. Lvm using the "write to a file" (at least I think you call it or something like that). I would have 2 questions:
    1) you can always using the virtual instruments to implement a block I calculate directly the average of these 10 thousand values ​​without having to go to the star on excel every time?
    2) is it possible to somehow remove the header that LabView a creates by default in the file. LVM when you save?
    I hope someone will give me an answer because I'm really losing a lot of precious time to pass each time data from lvm file to the excel.
    Thank you in advance for your advice.
    Solved!
    Go to Solution.

    Marco86,
    1. You should be able to read the data directly from the .lvm file in LV. Use the Express VI Read from Measurement File. You can wire the Signals output to the X input of the Mean.vi from the Mathematics >> Probability & Statistics palette.  LV will automatically insert a conversion from the Dynamic Data Type output of the Read to the 1D Array of Doubles that Mean needs.
    2. I rarely use the Write to Measurement FIle Express VI so I am not sure whether you can completely suppress the header.  If you use the Write to Spreadsheet File.vi you get a tab delimited text file containing only your data converted to text and delimiters.  You can create you own headers by writing a string array to the file before writing the numeric data.  Of course you can have complete control over everything in the file by using the low level file functions and data manipulation and string conversion functions.
    Lynn

  • How do I change this so the average has a decimal and zero?

    I'm trying to get this so that instead of like 90 I'll get 90.0
    oneString = JOptionPane.showInputDialog("Choose a test score 0-100");
              one = Integer.parseInt(oneString);
              twoString = JOptionPane.showInputDialog("Choose another test score");
              two = Integer.parseInt(twoString);
              threeString = JOptionPane.showInputDialog("Choose another test score");
              three = Integer.parseInt(threeString);
              fourString = JOptionPane.showInputDialog("Choose another test score");
              four = Integer.parseInt(fourString);
              fiveString = JOptionPane.showInputDialog("Choose another test score");
              five = Integer.parseInt(fiveString);
              sixString = JOptionPane.showInputDialog("Choose another test score");
              six = Integer.parseInt(sixString);
              sevenString = JOptionPane.showInputDialog("Choose another test score");
              seven = Integer.parseInt(sevenString);
              eightString = JOptionPane.showInputDialog("Choose another test score");
              eight= Integer.parseInt(eightString);
              nineString = JOptionPane.showInputDialog("Choose another test score");
              nine = Integer.parseInt(nineString);
              tenString = JOptionPane.showInputDialog("Choose another test score");
              ten = Integer.parseInt(tenString);
              elevenString = JOptionPane.showInputDialog("Choose another test score");
              eleven = Integer.parseInt(elevenString);
              twelveString = JOptionPane.showInputDialog("Choose another test score");
              twelve = Integer.parseInt(twelveString);
              thirteenString = JOptionPane.showInputDialog("Choose another test score");
              thirteen = Integer.parseInt(thirteenString);
              sum = (one+two+three+four+five+six+seven+eight+nine+ten+eleven+twelve+thirteen);
              mean = (sum / 13);
              System.out.println("The average of the scores is "+mean);

    I advise you to look at your code and ask yourself if it's efficient. What is you wan to add a few numbers to your program? You'll have to add a lot of lines of code.
    Ah well, here's the answer to your question (partially):
        double sum = (one+two+three+four+five+six+seven+eight+nine+ten+eleven+twelve+thirteen);
        double mean = (sum / 13);
    //...

  • Calculate the average of a collection

    Easy duck question:
    Where in standard library or common libraries like Jakarta I can find a set of method to compute the average of a collection of numbers, or an array of numbers.
    Yeah, I know I know, it is so easy to write it myself, but I am lazier than that. I just don't want to create a set of methods like
    long average(long[] longs);
    float average(float[] floats);
    int average(int[] ints);
    // etc...and then later find out that these are already in some common libs. Thanks folks.
    --lichu

    I mean easy duke question, not duck. :(
    public static double mean(double[] p) {
    double sum = 0;  // sum of all the elements
    for (int i=0; i<p.length; i++) {
    sum += p;
    return sum / p.length;
    }//end method mean
    And what if an empty double[] was passed in?

  • How to group result set to count values in several (2) attributes?

    Hi there,
    the (simplified) query at the bottom returns the following result set:
    OBJ_ID Attr 1 Attr2
    22674886 HAK44221 GEB132542
    22674886 HAK44221 GEB92751
    22674886     HAK44222 GEB92744
    22674886     HAK17113 null
    However, we need the number of different Attr 1 and Attr2 counted, which should result in the this:
    OBJ_ID Attr 1 Attr2
    22674886 3 3
    We trried using "group by grouping sets", "group by" and also took a glance at "cube" but didn't manage to get the desired result, mainly due to the fact, that Attr2 may contain null values.
    We managed to find a solution using a GTT or a view. Can anybody give a hint how to solve that without using temporary tables?
    Best regards
    Pat
    SELECT
    o.obj_id,
    o2.obj_name as Attr1,
    g.ckw_nis_nummer as Attr2
    FROM objekte o
    JOIN eigenschaftsdaten d0
    ON (o.obj_id = d0.obj_id AND d0.eig_id = 2525755)
    LEFT JOIN eigenschaftsdaten d8
    ON (d0.egd_wert=substr(d8.egd_wert,1,instr(d8.egd_wert, ' ')-1) and d8.eig_id=2525976)
    LEFT JOIN objekte o2
    ON o2.obj_id=d8.obj_id
    LEFT join gebaeude g
    ON o2.obj_id=g.parent_house_service

    Hi,
    That looks like COUNT (DISTINCT ...):
    SELECT       o.obj_id
    ,       COUNT (DISTINCT o.obj_name)          AS attr1
    ,       COUNT (DISTINCT g.ckw_nis_nummer)     AS attr2
    FROM        objekte o
    JOIN        eigenschaftsdaten     d0     ON   o.obj_id      = d0.obj_id
                               AND  d0.eig_id       = 2525755
    LEFT JOIN eigenschaftsdaten      d8     ON   d0.egd_wert = SUBSTR ( d8.egd_wert
                                                             , 1
                                              , INSTR (d8.egd_wert, ' ') - 1
                             and d8.eig_id=2525976)
    LEFT JOIN objekte          o2     ON  o2.obj_id      = d8.obj_id
    LEFT JOIN gebaeude           g     ON  o2.obj_id      = g.parent_house_service
    Depending on your data and your requirements, you may need to join some of the tables separatemly, do a GROUP BY to get attr2, and then join those results to the other tables.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data. WSimplify the problem as much as possible. For exam[ple, if your real problem involves 5 tables, but the part you don't understand can be shown with only 1 or 2 tables, then post sample data and results for those 1 or 2 tables only.
    Point out where the query above is getting the wrong results, and explain, using specific examples, how you get those results from the sample data in those places.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

Maybe you are looking for

  • Temp table Question

    In Oracle... can we use temp tables in procedures??? what would be the performance issue if I use a temp table in procedure?? After the procedure is run.. how can I assure that the temp table is deleted???

  • Number not being recognised;can't accept calls

    My iphone 4 cannot accept calls. The number is not bing recognised.

  • Gnome crashes when intalling new icon set.

    Whenever I drag a valid icon theme package into the "appearance" window to install it, the appearance program crashes. I'm certain it's a valid file as I've used it successfully in other distros with gnome. Also, nautilus opens a new window everytime

  • Exception in prepared execute on table SystemEvents: SELECT eventname,type,enabled,times,target,params FROM SystemEvents

    Hi all, I am trying to instal oracle webcenter in win server 2008 r2. but I am getting this exception (in "sites.log") and installation fails. Here's my stack trace. Any kind of help is appreciated. [2013-12-20 03:27:12,141 PST] [ERROR] [pool-7-threa

  • CC completely blank

    When I download CC from my Adobe account it installs and launches, but the dialogue box is completely blank; I cannot sign in or do anything except go to help. I have CC on my desktop already, this machine, the one I'm trying to install it on, is a l