Calculation of Averages
I need to be able to calculate the average difference between a total average on a single row for example
Value , AverageTotValue , Difference
2, 4, -2
4, 4, 0
6, 4, +2
preferably using Discoverer plus (although I could write a function if necessary)
Can anyone help ?
Hi , your query as you provided it , returns just one row , whereas mine returns three rows...so , i convert it to the following:
SQL> select value , avg_total , value-avg_total diff
2 from
3 (
4 select value , (select sum(value)/count(value)
5 from
6 (select 2 as value from dual
7 union all
8 select 4 as value from dual
9 union all
10 select 6 as value from dual)) avg_total
11 from (select 2 as value from dual
12 union all
13 select 4 as value from dual
14 union all
15 select 6 as value from dual)
16 )
17 /
VALUE AVG_TOTAL DIFF
2 4 -2
4 4 0
6 4 2[pre]
Now , as regards , the sql statistics...
Mine
[pre]SQL> with sample_data as (select 2 as value from dual
2 union all
3 select 4 as value from dual
4 union all
5 select 6 as value from dual )
6 select value , avg_total , value-avg_total diff
7 from
8 (
9 select value , (select sum(value)/count(value) avg_total from sample_data) avg_total
10 from sample_data
11 );
Ðñüãñáììá åêôÝëåóçò
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=3 Bytes=48)
1 0 TEMP TABLE TRANSFORMATION
2 1 LOAD AS SELECT
3 2 UNION-ALL
4 3 FAST DUAL (Cost=2 Card=1)
5 3 FAST DUAL (Cost=2 Card=1)
6 3 FAST DUAL (Cost=2 Card=1)
7 1 VIEW (Cost=2 Card=3 Bytes=48)
8 7 VIEW (Cost=2 Card=3 Bytes=9)
9 8 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6608_7E7090' (
TABLE (TEMP)) (Cost=2 Card=3 Bytes=39)
ÓôáôéóôéêÜ
2 recursive calls
8 db block gets
9 consistent gets
1 physical reads
604 redo size
598 bytes sent via SQL*Net to client
508 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
3 rows processed
Yours
SQL> select value , avg_total , value-avg_total diff
2 from
3 (
4 select value , (select sum(value)/count(value)
5 from
6 (select 2 as value from dual
7 union all
8 select 4 as value from dual
9 union all
10 select 6 as value from dual)) avg_total
11 from (select 2 as value from dual
12 union all
13 select 4 as value from dual
14 union all
15 select 6 as value from dual)
16 );
Ðñüãñáììá åêôÝëåóçò
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=3 Bytes=48)
1 0 VIEW (Cost=6 Card=3 Bytes=48)
2 1 VIEW (Cost=6 Card=3 Bytes=9)
3 2 UNION-ALL
4 3 FAST DUAL (Cost=2 Card=1)
5 3 FAST DUAL (Cost=2 Card=1)
6 3 FAST DUAL (Cost=2 Card=1)
ÓôáôéóôéêÜ
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
598 bytes sent via SQL*Net to client
508 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
3 rows processedCoclusion: Yours is much less costly to system and so quicker.....
I have to confess that i have not thought this format ........I have learned something today....!!!!!!
I have get accustomed to using the with clause... but i may reconsider it....!!!!!!
Thanks , a lot for your valuable remarks....(as always)...!!!!
Simon
Similar Messages
-
Problem in calculating the Average Daily Requirement
Hello all,
I didn't understand how the system calculates the average daily requirement in Dynamic Safety Stock process. The following process flow in given in SAP notes to find how the system calculates the average daily requirement:
1. The system uses the defined parameters to determine the number of days used for calculating the average daily requirements. If the period is defined as a week, the period length as standard days (5 days) and the number of periods as 2, the system divides the total of the requirements by 10 days.
2. The system then calculates the total of the requirements for this period.
The system takes into account all requirements in the current period, even requirements that lie in the past but are still in the current period. For example, if the planning run is carried out in the middle of the month, then those requirements that were planned at the beginning of the month are also included in the calculation of the average daily requirements.
3. The average daily requirement is calculated using the formula:
Requirements in the specified number of periods / Number of days within the total period length
I have run MRP on 02/23/2009 and the following results are generated in stock requirement list of the component part:
Date Dependent Requirement MMSA Schedule Lines Quantity
3/3/2009 10 31
3/11/2009 20 20
3/31/2009 30 30
4/14/2009 40 49
4/22/2009 50 50
4/29/2009 60 60
5/11/2009 70 55
5/21/2009 80 80Hi,
In addition to my previous reply,
If you did following setting -
Range of coverage in first period -
min - blank
tgt - 7
max - blank
number of periods - blank
The system will calculate the safety stock for 7 days for each period; i.e., 7*3=21 and it will generate plnd orders as
week1 = 51
week2 = 14+21 = 35
week3 = 10+21 = 31
week4 = 30+21 = 51
If you want to restrict your calculation till 2 periods then make following settings -
Range of coverage in first period -
min - blank
tgt - 7
max - blank
number of periods - 2
Range of coverage in second period -
Make all blank
Range of coverage in the rest of the horizon -
min - blank
tgt - 3
max - blank
It means for first two weeks the safety stock will be 21 (equivalent to 7 days) and for rest of the horizon it will be 3*3 = 9 (equivalent to 3 days)
The Plnd orders will be -
week 1 = 51
week 2 = 35
week 3 = 14+9 = 23
week 4 = 30+9 = 39
and so on.
Regards,
Amol -
Auto check calculating the Average
I do not know how to approach an issue with my form, so any help or quide will be appreciate very much!
For a Performance Form I have 5 sections for the managers to fill in.
Every section includes an Assessment drop down list with 5 items to select from.
Items for DDList (Named:Assessment):
Outstanding
Exceeds Expectations
Meets Expectations
Needs Improvement
Does Not Meet Expectations
Final at the end of the form I have a section named
OVERALL SUMMARY OF PERFORMANCE with 5 check boxes named:
Outstanding
Exceeds Expectations
Meets Expectations
Needs Improvement
Does Not Meet Expectations
Is it possible with a script(Calculating the average?), AUTO to check(one of the check boxes for the Overall sum of performance?
THANK YOU
Hi Niall, I took your advise form your last sample cindle you have send me, I am close but still I have a problem at the end of the line!
Here what I have till now:
On change event for the Area1 the script below:
switch
(xfa.event.newText){
case
"Outstanding":
NumericField1.rawValue
= "5";
break
case
"Exceeds expectations":
NumericField2.rawValue
= "4";
break
case
"Meets expectations":
NumericField3.rawValue
= "3";
break
case
"Needs improvement":
NumericField4.rawValue
= "2";
break
case
"Does not meet expectations":
NumericField5.rawValue
= "1";
break
For a NumericField1(Score for Outstanding) on Calculate event the script:
var vScore=0 ;
for (var i=0; i<5; i++){
if (xfa.resolveNode("optionA[" + i + "]").rawValue=="5")vScore
+=xfa.resolveNode("optionA[" + i + "]").rawValue;}
NumericField1.rawValue= vScore ;
This I am getting(for NumericField1) is for example select Outstanding for all DDL is:55555 than 25 which is the desire!
How I can make it work, where is my mistake?
Thanks Niall -
Formula For Calculating An Average
I have the below formula in a group footer (Group Footer #1) that is suppose to calculate the average between the accumlated number of days (i.e. {@Days Taken}) divided by the number of records (i.e. Count (). The value for the number of days is correct and the value for the record count is correct. For some reason the value for the average is not correct. The average is not re-calculating when there is a new group. The average is repeated for each group. Is there anything wrong with this formula ?
Sum ({@Days Taken})/Count ()Lenell,
You need to tell it to divide the sums per group.
So;
Sum ({@Days Taken},)/Count (,)
Replace with the field that you are grouping on. -
Wallboard - Calculating daily average wait time
In Historical Reporting, if we look up a queue's average wait duration for the day we are given 5:34.
At the same time, if I pull up avgWaitDuration in RtCSQsSummary, I am given 190505. What number is this? Seconds? if in seconds, and the total calls answered for that queue is 248, then I should be able to divide 190505 by 248. When I do that, I get 768 seconds. 768 (12:48) is a far cry different from 334 (5:34). Where am I going wrong?Ok, I determined that the number is not actual ASA, but apparently "avg queue time". I assume this to mean the clock starts when the caller is placed in the queue, after completing the call tree.
I figured out how to calculate the time provided, and it matches the time in History Reporting for the "avg queue time". But the time we ACTUALLY want is the "avg speed to answer", as found in History Reporting for each queue.
What table would I find the ASA from the time the caller enters the call tree? -
Calculating weekly average in reports
I have a report that looks like:
Vol previous 7 day average
12
34
45
56
34
98
12 41.6
45 46.2
76 52.3
89 etc...
12
What would be the best way to do the previous 7 day average values in Reports 3.0.
Thanks for any assistance.
nullI have a table like this:
ViewID
ViewDateTime
I would like to have the weekly average of views and
have an output that looks like:
[Weekly Avg] [Week Starting]
Any help would be greatly appriciated.If I have well understood, then this will help you: (format is the format of your choice)
SELECT Avg(ViewID) "weekly Avg",
TO_CHAR(TRUNC(MIN(ViewDateTime), 'WW') + 1, 'format')
FROM t
GROUP BY TO_CHAR(ViewDateTime, 'YYYY') || TO_CHAR(ViewDateTime, 'WW')I began editing before your explanation so you can suppress the year if all your records are in the same one.
Message was edited by:
Michel -
<p>I have four groupings, Domain, Area, Priority (3rd level of grrouoping) and then Problem ID. Priority group could have values such as '1', '2', '3', '4' and '5' with corresponding "average" age formula on these group level. values.</p><p>Example: 1 Avg Age= 30</p><p> 2 Avg Age= 45</p><p> 3 Avg Age= 69</p><p>Reguirement: Display group name values and their corresponding average formula on a single line/row.</p><p>Sample Solution: Priority 1 = 30, Priority 2 = 45, Priority 3 = 69 </p><p> ***solution above should be displayed/concatenated on one line.</p><p>Your help is greatly appreciated, thank you in advance.</p>
So right now - your report looks like this
GroupHeader 1
GroupHeader 2
Priority 1 = 50 (actual display of Group 3)
Priority 2 = 75 (actual display of Group 3)
Priority 3 = 45 (actual display of Group 3)
Priority 4 = 9 (actual display of Group 3)
Priority 5 = 8 (actual display of Group 3)
And you want to change that so that it displays horizontally.
If there will only ever be 5 priorities, I think I would cheat the system a bit. Create a formula that runs at the group 3 level and dumps the values into 5 separate variables (formula below).
Then create 5 separate display formulas and put them in Group Footer 2 (if you already have a GF2 - then create a second one and move it above your current GF2). Suppress the G3 section and you should be close to what you are after (unless you also have detail sections, then we'll need to revisit).
This could also be accomplished with a multi-column subreport at the G2 or G3 level if you need more flexibility.
formula *******
numbervar priority1;
numbervar priority2;
numbervar priority3;
numbervar priority4;
numbervar priority5;
if {DB.Priority} = 1 then priority1:= {@avgGroupPriorityAvgAge}
else if {DB.Priority} = 2 then priority2:= {@avgGroupPriorityAvgAge}
else if {DB.Priority} = 3 then priority3:= {@avgGroupPriorityAvgAge}
else if {DB.Priority} = 4 then priority4:= {@avgGroupPriorityAvgAge}
else if {DB.Priority} = 5 then priority5:= {@avgGroupPriorityAvgAge} -
BEx calculation for 'average sales order value'
Hi all,
Can someone tell me how to use BEx query function to compute the <b>'average sales order values' by month</b>? Thank you.
J.Hi John,
You've two characteristics in the rows, right? Calendar Month and Order Type.
Try the option Calculate Result as Average of All Values and
Calculate Single Value as Nothing Defined? See if this works.
Or else in Modelling,
In the Info Object Create/Change screen, you can specify an Exception Aggregation based on
<b>Aggregate Reference Characteristic</b> Calendar Month.
I think there's an option for Average Values in the <b>Exception Aggregation</b> tab.
For more Information,
http://help.sap.com/saphelp_nw04/helpdata/en/75/21054da1392649948e5b94e4fc4bce/content.htm
Hope this helps.
Regards
Hari
Message was edited by: Hari Krishnan K -
Formula for calculating the average takings for a given day in the week?
I would like to calculate the average takings for each day of the week for a given financial year.
Rick,
I've looked at your document, made some additions and returned it to you. In your document you were not only using AVERAGE, but also MIN and MAX. Unfortunately, MIN and MAX don't have "IF" versions, so they can't be used to selectively operate on data matching criteria in a range.
What I did to accommodate the need for MIN and MAX was to add a column for each criteria, in this case the different days of the week.
In your document you also indicated the need for a Chart to graphically summarize the performance by day of the week. I rearranged your summary stats table to facilitate creating a chart from that table. I chose the mixed category chart with Bars for Min and Max and a Line for Average.
Following are Screen Shots for the modified Data table, the Stats table and the Chart:
The key expressions are:
For Monday receipts:
=IF(WEEKDAY($B)=2, $G, "")
For Monday Minimum:
=MIN(INDIRECT("Ledger::"&CHAR(70+ROW())))
You had pre-filled Column A with 3-letter abbreviations of the Days of the Week. I am not sure this is important, since you could have formatted the Date (Column B) to show the same information, but I didn't like seeing the abbreviations for days that didn't have data entered yet so I replaced the text with an expression...
=IF(LEN(B)>0, LEFT(DAYNAME(WEEKDAY(B)), 3), "")
I seems that you may have filled the table with several months worth of rows of Mon, Tue, etc. Now, if you wish, you can trim the blank rows to just a few and add more as you need them.
Let me know if you have any questions about maintaining the document.
Jerry -
Calculating an average in a Pivot Table column
Hello everyone,
I have a Pivot Table..
One Measure only
In Rows:
I have 3 fields: FieldA, FieldB, FieldC
In Columns:
I have 1 field: Field D
From field D, I have created 5 calculated items (to single out the column values) and a Total calculated item column to sum the 5 calculated items.
I have also enabled the Column Grand Total.
Now, I want to create another calculated item (I think?) to calculated the (Total calculated item column) / (Column Grand Total)
I tried creating a calculated item by doing the following (Total calculated item column) / sum(*), but this does not output anything.Re: how to Make a report from two cubes
This link will help you. -
Generic_137111-02 sun4v sparc SUNW,SPARC-Enterprise-T5220 Solaris 10:
I have couple of questions:
1. mpstat shows it has 63 CPUs but the spec says T5220 have 8 cores.
2. I don't understand what is threading technology in CPUs. What's the difference as compared to cores
3. How do I calculate load averages? When I do a top I don't know how to convert it into this CPU threading technology. How do I know if machine is overloadedThe Niagara processor is designed so there can be 8 parallel simultaneous threads (Hardware threads) running on a single core.
The T2 processor (Niagara 2) is capable of 8 cores, each capable of 8 parallel threads. So, effectively one T2 can run 64 threads simultaneously.
[http://blogs.sun.com/glennf/entry/getting_past_go_with_sparc|http://blogs.sun.com/glennf/entry/getting_past_go_with_sparc]
[http://blogs.sun.com/glennf/tags/cmt|http://blogs.sun.com/glennf/tags/cmt]
I'd recommend going through these two links (see above). It will save you a lot of grief when you go from single-threaded admins to multi-threaded admins. -
Calculating Average on a Pivot table- Not calculating correct
Hello All BI Techie's,
I have a requirrement, which is calculating the average out of a column , this column is aggreated by sum in the rpd.
Month Year Associate Headcount Involuntary Termination Count (Associates)
2012 / 07 18878.0 55
2012 / 08 18817.0 53
2012 / 09 18770.0 63
Grand Total 18770.0 17
Now, I want calculate a column which gives the average of Associate Headcount, ( 18878+18817+18770)/3 , how I can achieve that?
I tried, using avg(associate headcount), it not returning correct average, any insight?
Please share your ideas.
Thanks,
BalaThanks Srini, The tried your solution but still the problem exists.
I have created a new column, called Avg Headcount and entered condition in the column, I am using pivot table.
max(rsum("Workforce Profile Facts"."Associate Headcount"))/max(rsum(1))
Actual Results
Month Year Associate Headcount Involuntary Termination Count (Associates) Avg Headcount
2012 / 07 18878.0 55 18907.8
2012 / 08 18817.0 53 18878.0
Grand Total 18817.0 108 18878.0
Expected results
Month Year Associate Headcount Involuntary Termination Count (Associates) Avg Headcount
2012 / 07 18878.0 55 18878
2012 / 08 18817.0 53 18817
Grand Total 37695.0 108 37695/2 = 18847.5
Eeven my Associate Headcount, pivots grand total was wrong, my instanceconfig.xml already setted to aggregate enabled. -
DP macros, calculating average values over a period of time
Hello
I have a key figure row, for the future i want this key figure to contain the average of a different key figure row over the last year.
How would you go about calculating the average value of a key figure row over a period of time and then assigning this value to another key figure?
I've tried variatons of AVG() and SUM() & SUM_CALC a but none of them seem to get me anywhere, i may not understand completely how rows & values work so any tips would be helpful.
Iin pseudo-logic: what i need to do is:
Calculate the average value of a key figure row over a given period (the last year)
Store this value somewhere, in regular programming it'd be a variable of some kind.
Assign this value to another key figure row 18 months into the future.
Regards
Simon Pedersen<H5>Hi Simon,
If you are a technical guy, you can create a BADI implementation for that macro and manipulate the matrix data like the way you want.
the procedure to implement a BADI is
1.SPRO --> SAP SCM - Implementation Guide --> Advanced Planning and Optimization --> Supply Chain Planning --> Demand Planning (DP) --> Business Add-Ins (BAdIs) --> MacroBuilder --> Additional Functions for Macros.
create a new implementation by copying the class for the BADI defenition '/SAPAPO/ADVX' and write your own code in the method '/SAPAPO/IF_EX_ADVX~USER_EXIT_MACRO '. There is a sample code and proceedure explaining how to handle the data in the internal tables C_T_TAB and C_T_TAB_OLD. the calculations can be made with help of I_T_LINES, I_T_COLS which are rows and columns tables.
find out the the row and columns of the grid to be read and do calculation and then put the result in the desired cell.
Please let me know if you need further assistance.
Regards,
Srini.
Award points for the helpful answers <H5> -
Average calculations with dates
Hi,
I have a problem with calculating the average time a call lasts. I have a start and finish time to a call that are stored in a database in datetime format. How do i find out the time of the call and then get an average over the number of calls made in a month. I have to hold the time format and show the result in the same time format that is in the database. How do you do this? I know how to do it with decimals but how to manipulate time confuses me.
Cheers
NiallYou can use the method getTime() of the class java.sql.Timestamp, which returns milliseconds in the long type, and toString() method of java.sql.Time may serve your aim here.
-
HELP !!! average calculation
Hi,
I want to calculate the average number of products sold by an agent. The formula is Avg = (nr. prod / nr. clients) where nr.prod is the number of unique products sold to a customer and nr. clients is the number of customers.
It works just fine when the customer is drilled down. In this case nr.prod is calculated fine, nr.client = 1 and the subtotal is calculated as average - that's what i want.
The problem occurs when I remove the customer drilldown - in this case the nr.prod is no more calculated as a sum of products for all the agent's customers but as the number of products for this agent.
The nr.prod and nr.client are calculated key figures as count all values for reference characteristic customer/material (in the aggregation exception).
thanx
danielthe average is calculated as nr_p/nr_c.
result with customer drilldown:
agent customer average=nr_p/nr_c nr_p nr_c
A X1 3,00 3,00 1,00
X2 2,00 2,00 1,00
X3 4,00 4,00 1,00
X4 5,00 5,00 1,00
<b>result 3,50 14,00 4,00</b>
if I hide customer then i'll have:
agent average=nr_p/nr_c nr_p nr_c
A <b>0,75 3,00 4,00</b>
nr_c = calculated key figure, aggregation =summation, aggregation exception= count all values, ref. characteristic = 0customer
nr_p = calculated key figure, aggregation =summation, aggregation exception= count all values, ref. characteristic = 0material
the problem is that I need this nr_p as sum of nr_p for each customer. How can I make this sum without the customer column ?
Maybe you are looking for
-
I mistakenly asked iTunes to download a TV series and I can't get it to stop trying to download it. how do I kill the download?
-
How to work with a workflow in Webdynpro
Hi Team, I am new to webdynpro ABAP, i have a scenario I have a work flow id with me, i want to start this workflow from a webdynpro application, 1. wedynpro application contains a list of inputs and user1 inputs this data that i have stored n
-
Excel process does not end properly
Hello All. I am using excel in my program writing data into it an excel workbook and then later on reading data from it. I have written down the code of closing excel worlkbook and shutting down excel application hence releasing the handles for it. B
-
SAP for Professional Services pack
Hi Guru's, Please provide me the information on the following 1) Can we install SAP for Professional Services pack on a running ECC 6 system? 2) What is the Impact on existing ECC 6 on this installation? 3) What are the perquisites for
-
Low bass level after burning CD from iTunes.
I like lots of bass through my subwoofers when I'm driving. Unfortunately within the last 6 months or so, every cd I've burned through iTunes has low bass level. I can tell the difference when I compare an original cd to a burned cd. Is it normal for