Weighted average calculation in query
Hello
i'm having some issues calculating an weighted average...
imagine the next scenario
LINE | FORMAT | TIME | WORKERS
10 | 000123 | 10 | 5
10 | 000123 | 350 | 2
10 | 000123 | 75 | 1
From this i need the wighted average of the nr workers considering the time they were working
so, to calculate that i have to do for example:
(time * worker)/total time
in numbers...
((105)+(3502)(75*1))/(10350+75)
=1,89 workers for that line, for that format and for all that time
I am able to do that formula inside bex analyser, however when the user drills down the report or sorts the key figures in other order the result is not correct.
any suggestions?
Best regards
Hi Ricardo
What we did, in a similar case, we used two formulas. The first one was the calculation (time * worker) with exception aggregation (summation).
The second formula was the previous formula divided to time.
The trick is which characteristic to use for the aggregation in the first formula, i think you should have the most detailed one.
Then i believe the two formulas will calculate correctly the weighted average based on any selections/analysis that you do.
Regards
Yiannis
Similar Messages
-
How does xMII calculate a time weighted average?
I am in the process of doing data validation for tag query result sets from IP21 process data. The comparison is against an IP21 add in to Excel which generates numbers that don't correspond to the numbers generated by xMII. The add in appears to be generating values according to a Time Weighted Average but it is returning different numbers. The differences are not large, but it is a virtual certainty that a plant manager or process engineer will take issue. So we (I and my client) would like to know how to explain the difference in the calculation results. We suspect that it involves interpolation for missing data, but would like to know for sure. We are also checking the IP21 algorithm(s) to make sure we understand how it works. Any insight would be appreciated.
Rick/Jeremy,
I am still not getting the same values. My correlation testing is in Excel 2003. In xMII I have the number format set to 0.000000. Typical values in the result set are coming in with five decimal place accuracy. I am using one hour's data at 1 minute intervals with date accuracy to the second and the data is compressed to 52 actual datapoints. The time range is 11/07/2007 00:00:00 to 11/07/2007 01:00:00. It is in HistoryEvent mode. The row count is set to 20000.
When I run the TWA from xMII, I get 22773.576740.
When I ran my first algorithm in Excel, I get 22767.37321. When I made the change to what Rick said, I get closer but am still off and get 22769.35835. Can either of you (or anyone else) explain the delta? I have rerun both calculations twice on all three sides and get the same results.
Here is my data:
DateTime ActualValue
11/07/2007 00:00:01 23841.572266
11/07/2007 00:01:01 23608.240234
11/07/2007 00:02:01 23238.177734
11/07/2007 00:03:01 23373.197266
11/07/2007 00:04:01 23244.857422
11/07/2007 00:05:02 23408.943359
11/07/2007 00:06:01 23138.939453
11/07/2007 00:07:01 23325.080078
11/07/2007 00:08:01 23433.609375
11/07/2007 00:10:01 22783.115234
11/07/2007 00:11:01 22642.421875
11/07/2007 00:12:01 22226.654297
11/07/2007 00:13:01 22741.773438
11/07/2007 00:14:01 22611.898438
11/07/2007 00:16:01 22810.580078
11/07/2007 00:17:01 22404.023438
11/07/2007 00:18:01 22627.966797
11/07/2007 00:19:01 22672.619141
11/07/2007 00:20:02 22268.031250
11/07/2007 00:21:01 21770.136719
11/07/2007 00:22:01 22877.025391
11/07/2007 00:23:01 22565.330078
11/07/2007 00:24:01 22781.949219
11/07/2007 00:25:01 22324.345703
11/07/2007 00:26:01 22170.953125
11/07/2007 00:27:01 21960.464844
11/07/2007 00:30:01 22495.685547
11/07/2007 00:31:01 21899.714844
11/07/2007 00:32:01 22487.603516
11/07/2007 00:33:01 22723.382812
11/07/2007 00:34:01 22461.189453
11/07/2007 00:35:01 22823.869141
11/07/2007 00:36:01 22599.085938
11/07/2007 00:37:01 22902.572266
11/07/2007 00:41:01 22894.148438
11/07/2007 00:42:01 22724.144531
11/07/2007 00:43:01 22659.437500
11/07/2007 00:44:01 23105.324219
11/07/2007 00:45:01 22634.763672
11/07/2007 00:46:01 22929.582031
11/07/2007 00:47:01 22475.185547
11/07/2007 00:48:01 22739.755859
11/07/2007 00:50:01 22864.958984
11/07/2007 00:51:01 22556.917969
11/07/2007 00:52:01 22794.998047
11/07/2007 00:53:02 22934.748047
11/07/2007 00:54:01 23206.296875
11/07/2007 00:55:03 22412.509766
11/07/2007 00:56:02 22935.718750
11/07/2007 00:57:01 23924.460938
11/07/2007 00:58:01 22918.369141
11/07/2007 00:59:02 23048.748047
Message was edited by: MAppleby
Michael Appleby -
Creating Weighted Average Sub-Totals in Standard Apex Report
Based upon the below query, I am trying to have a Standard SQL report produce Weighted Average sub totals for 4 columns
SELECT Pool
, order_by
, Pool_order
, Perf_Non_Perf
, CurrBal
, LowVal
, HighVal
, LossHigh
, LossLow
, CalcCurrBal
, DECODE(CurrBal,0,0,(LowVal/CurrBal * 100 )) AS LowPercent
, DECODE(CurrBal,0,0,(HighVal/CurrBal * 100 )) AS HighPercent
, DECODE(CalcCurrBal,0,0,(LossHigh/CalcCurrBal * 100)) AS LossHighPercent
, DECODE(CalcCurrBal,0,0,(LossLow/CalcCurrBal * 100)) AS LossLowPercent
From (
SELECT Pool
, 1 as order_by
, Pool Pool_order
, Perf_Non_Perf
, Sum(Current_Balance) AS CurrBal
, Sum(Low_Value) AS LowVal
, Sum(High_Value) AS HighVal
, Sum(Calculated_Cumm_Loss_High) AS LossHigh
, Sum(Calculated_Cumm_Loss_Low) AS LossLow
, Sum(Current_Balance_to_Calc_Cumm_L) AS CalcCurrBal
FROM Current_Data
GROUP BY Pool, Perf_Non_Perf
ORDER BY Pool, Perf_Non_Perf DESCThe columns in question are:
LowPercent
HighPercent
LossHighPercent
LossLowPercent
Any ideas other than using a union to add the sub-totals in as a separate query (trying to keep this confined to one query if possible)..
Thank you,
Tony Miller
Dallas, TXTony,
The PL/SQL forum may answer this better but had you considered the ROLLUP or CUBE GROUP BY functions? ROLLUP would look like this in your query:
SELECT pool,
order_by,
pool_order,
perf_non_perf,
currbal,
lowval,
highval,
losshigh,
losslow,
calccurrbal,
SUM (DECODE (currbal, 0, 0, (lowval / currbal * 100))) AS lowpercent,
SUM (DECODE (currbal, 0, 0, (highval / currbal * 100))) AS highpercent,
SUM (DECODE (calccurrbal, 0, 0, (losshigh / calccurrbal * 100)))
AS losshighpercent,
SUM (DECODE (calccurrbal, 0, 0, (losslow / calccurrbal * 100)))
AS losslowpercent
FROM ( SELECT pool,
1 AS order_by,
pool pool_order,
perf_non_perf,
SUM (current_balance) AS currbal,
SUM (low_value) AS lowval,
SUM (high_value) AS highval,
SUM (calculated_cumm_loss_high) AS losshigh,
SUM (calculated_cumm_loss_low) AS losslow,
SUM (current_balance_to_calc_cumm_l) AS calccurrbal
FROM current_data
GROUP BY pool, perf_non_perf)
GROUP BY rollup (pool,
order_by,
pool_order,
perf_non_perf,
currbal,
lowval,
highval,
losshigh,
losslow,
calccurrbal)
ORDER BY pool, perf_non_perf DESCJeff -
Weighted average total displaying as average
Dear BI Guru's,
one of my report Weighted average total value displaying incorrect values, for example
Clinker Value Clinker Rate
(Rs in lacs) (Rs/MT)
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
342.00
1.21
342.00
0.72
342.00
0.80
342.00
2.73
19.59
Clinker Rate MT should display 342 instead of 19.59, i was applied exception aggregation for clinker value Total and ref characteristic plant. same exception aggregation applied to net quantity keyfigure.
Clinker rate calculation = Clinker value/Net quantity,
thanks in advance who replay as earliest.
regards
Ramesh GWhat is the line item infoobject in your data which is causing given list of records?
Try TOTAL with line item infoobject as ref char but not plant.
Try with constant selection on your KF to display 342. -
Hi,
I am finding some problem while doing the Average Calculation in the Query.
My data is like this:
Batch Stock PO Qty STO Qty
B1 1000 1000 200
B1 1000 1000 500
In the output I want:
Batch Allocated Unallocated
B1 700 300
The calculation for Unallocated is ( Stock - Allocated ).
Right now I am getting:
Batch Allocated Unallocated
B1 700 1300
What I want is to do the Average of the Stock Qty and then subtract that from the Allocatde Qty.
Can anyone help out?
Regards,
SoumenHi,
You can use the Calculated key figure (if you need top 10)...
Regards
sathis -
PowerPivot formula for row wise weighted average
Hi everybody,
I have a table in `PowerPivot` which contains the logged data of a traffic control camera mounted on a road. This table is filled the velocity and the number of vehicles that pass this camera during a specific time(e.g. 14:10 - 15:25). Now I want to know
that how can I get the average velocity of cars for an specific hour and list them in a separate table with 24 rows(hour 0 - 23) where the second column of each row is the weighted average velocity of that hour? A sample of my stat_table data is given below:
count vel hour
133 96.00237 15
117 91.45705 21
81 81.90521 6
2 84.29946 21
4 77.7841 18
1 140.8766 17
2 56.14951 14
6 71.72839 13
4 64.14309 9
1 60.949 17
1 77.00728 21
133 100.3956 6
109 100.8567 15
54 86.6369 9
1 83.96901 17
10 114.6556 21
6 85.39127 18
1 76.77993 15
3 113.3561 2
3 94.48055 2
In a separate `PowerPivot` table I have 24 rows and 2 columns(column1 is for hours and column 2 for weighted averages) and when I enter my formula, the whole rows get updated with the same number. My formula is:
=sumX(FILTER(stat_table, stat_table[hour]=[hour]), stat_table[count] * stat_table[vel])/sumX(FILTER(stat_table, stat_table[hour]=[hour]), stat_table[count])
I have also asked this question at
Stackoverflow.Hi Reza,
According to your description, you need to calculated the average value of Vel group on Count and Hour, right?
I have tested it on my local environment, the sample expression below is for you reference.
=CALCULATE(sum(Sample[Vel]),ALLEXCEPT(Sample,Sample[Count],Sample[Hour]))
If this is not what you want, please elaborate the issue, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support
Thank you,
Yes it works. But I decided to use a 'measure' rather than a calculated column. My measure's formula is:
=SUMX(stat_table, [vel] * [count]) / SUMX(stat_table, [count]) -
FIFO to weighted Average method
Hi Gurus
my client want to switch from FIFO to Weighted Average method in INVENTORY,can someone please assist as to what the possible issues that might arise,the step or any procedure that need to be followed and as to whether is safe to make that change.
your assistance will be greatly appreciatedHi Chithra,
I'm a bit confused by your question. FIFO is just an inventory management method, while moving average price is simply a way SAP calculated the value of the stock. How is your company keep track of the inventory value in FIFO? What kind of calculation or formula does your company apply to get the month-end closing value? There shouldn't be much impact, I think. Because, at the initial stage, you will be using the value from old system, upload it to SAP to use it as opening value for your stock.
Thanks and regards,
Anisah -
Average calculation with joins
Hi all,
Please have a look here.,
Re: average calculation using sql
My Question is :
Is it possible to do a join here,
so that in where condition thistable.id=newtable.id
and in column area i need projects from new table.
i.e.,
Projects Name Remark SUM AVG
I tried with this query..
SELECT Projects,Name,Remark, SUM(work_hrs), AVG(work_hrs) FROM (
SELECT name,remark ,a.id,b.id,start_dt,end_dt,SUM(end_dt-start_dt) OVER (PARTITI
N BY name,remark ORDER by Name) work_hrs
FROM T a,T1 b) where a.id=b.id
GROUP BY ROLLUP(name,remark);
But o/p is not as i expect..
Thanks in advance...The alias 'b' does not exist outside of the subquery/inine view. Try to alias your subquery for clarity then refer to it;
SELECT MAX(sub.sr_pm_name), sub.ts_desc, sub.ts_remarks, AVG(sub.work_hrs)
FROM (SELECT ts_desc,
ts_remarks,
b.sr_id,
a.ts_srid,
b.sr_pm_name,
ts_expected_date,
ts_actual_date,
SUM(ts_actual_date - ts_expected_date) over(PARTITION BY ts_desc, ts_remarks ORDER BY ts_desc) work_hrs
FROM t_status_report b, t_task_status a
WHERE b.sr_id = a.ts_srid) sub
GROUP BY ROLLUP(ts_desc,
ts_remarks);Another way that might be easier to follow is to use the WITH clause;
WITH sub AS (
SELECT ts_desc,
ts_remarks,
b.sr_id,
a.ts_srid,
b.sr_pm_name,
ts_expected_date,
ts_actual_date,
SUM(ts_actual_date - ts_expected_date) over(PARTITION BY ts_desc, ts_remarks ORDER BY ts_desc) work_hrs
FROM t_status_report b, t_task_status a
WHERE b.sr_id = a.ts_srid)
SELECT MAX(sr_pm_name), ts_desc, ts_remarks, AVG(work_hrs)
FROM sub
GROUP BY ROLLUP(ts_desc,
ts_remarks); -
Using Perpetual Weighted Average (PPAC) as costing Method in R12.1.1
I have setup a company having two operating units both using same ledger and same calendar. One of the operating unit is using Period Moving Average Costing (PMAC) and the other one is using Perpetual Weighted Average (PPAC). Both operating units have manufacturing organizations where batches are being created and cost of finish product is based on the ingredients consumption of the batch. My issue is that I cannot figure out how the cost is being computed for an item that has been produced from a production batch using the PPAC method. For the PMAC, I can see that it is using previous month balance and cost and compute it with current transactions data. But for PPAC, it is difficult to analyse the cost, and the only explanation from oracle note said that the calculations is based on all transactions within ALL period in the costing calendar. How will I calculate the cost for a specific item if the calendar started from July 2009. Should I compute the cost for an item for all transaction from July 2009 until April 12 ? Should I keep different calendar for each financial year or only one calendar is enough?
I just waring you to be careful about PPAC.
1. The value cost adjustment and unit cost adjustment will use to calculate item cost in single period only.
2. Cost revaluation will make you can't reconcile between GL amount and inventory valuation.
3. If your stock is 0 at the end of period your GL amount will still have value but inventory valuation is 0. -
Weighted Average in Pivot View
Hi,
Can you please throw some light on the below scenario based on weighted average:
For Ex:
Cloumn1---Column2-----Column3
R1-----------Line Item1--10
R1-----------Line Item2--20
R2-----------Line Item3--30
R2-----------Line Item4--40
Now i am trying to achieve weighted average based on the group by of Column1.
10+20=30==>30/2=15
30+40=70==>70/2=35
Before raising this thread, i had a look at the below URL:
http://siebel.ittoolbox.com/groups/technical-functional/siebel-analytics-l/weighted-average-for-fact-column-values-1242947
Can you please let me know how we can achieve this in the pivot view(OBIEE 10.1.3.4.1).
Your help is highly appreciated.
Thanks in Advance
SivaHi,
Try-
AVG(measure_col by column1)
And try making in the column formula -Aggregation Rule (Totals Row)-->Average
And also try making the aggregation rule in the pivot table of the column as-->Average
Hope this helped/ answered.
Regards
MuRam
Edited by: MuRam on Jun 11, 2012 4:46 AM -
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,
PeeyushHi 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 -
How can I activate the average calculation with cl_salv_hierseq_table class
Hi there,
Iu2019m using class cl_salv_hierseq_table to display a two level hierarchy (header and item) list.
For some reason it seams that those calculations are active by default with class cl_salv_table but not for cl_salv_hierseq_table.
I tried every suggestion from the class documentation and SAP help and nothing seams to work, the menu calculation options are always inactive except for the total calculation.
After the cl_salv_hierseq_table=>factory...
And before cl_salv_hierseq_table->display( )
I triedu2026u2026.
cl_salv_aggregations = cl_salv_hierseq_table->get_aggregations( 1 )
cl_salv_aggregations->add_aggregation( 'COLUMN1' )
COLUMN1 is a currency column in header level table
u2026u2026..
cl_salv_aggregations = cl_salv_hierseq_table->get_aggregations( 2 )
cl_salv_aggregations->add_aggregation( 'COLUMN2' )
COLUMN2 is a dec column in item level table
u2026u2026..
cl_salv_aggregations = cl_salv_hierseq_table->get_aggregations( 2 )
cl_salv_aggregations->add_aggregation( columnname = 'COLUMN2' aggregation = if_salv_c_aggregation=>average )
u2026u2026..
cl_salv_aggregations = cl_salv_hierseq_table->get_aggregations( 2 )
cl_salv_aggregations->set_aggregation_allowed( 'COLUMN2' )
u2026u2026..
cl_salv_aggregations = cl_salv_hierseq_table->get_aggregations( 2 )
cl_salv_aggregations->set_numerical_aggregation( ).
cl_salv_aggregations->set_aggregation_allowed( 'COLUMN2' )
cl_salv_aggregations->add_aggregation( columnname = 'COLUMN2' aggregation = if_salv_c_aggregation=>average )
u2026u2026..
cl_salv_aggregations = cl_salv_hierseq_table->get_aggregations( 2 )
cl_salv_aggregations->add_aggregation( 'COLUMN2' )
cl_salv_aggregation = cl_salv_aggregations->get_aggregation( 'COLUMN2' )
cl_salv_aggregation->set( if_salv_c_aggregation=>average )
Any help will be appreciated!Thanks Harsh Bhalla,
Subtotals can be built (displayed) at Header Level Only, true but the values to calculate those totals can come from either header or item level, otherwise it wouldnu2019t be of much use would it?
Anyway my question is how to activate the average calculation as well because the totals calculations is already active for either item or header level by default.
For reference when on the display layout Iu2019m referring to the menu Edit -> Calculate -> Mean Value. -
HI Experts,
I need some calculations at query level,
find the below user requirement.
And one more thing we are not authorised to use Customer exits.
SELECT
[FA No] As [FA No],
[FA Description] As [FA Description],
Sum( CASE WHEN [Posting Date] < @fromDate THEN Amount ELSE 0 END) AS [Starting Balance],
Sum( CASE WHEN [Posting Date] >= @fromDate AND [Posting Date] <= @toDate THEN [Debet Amount] ELSE 0 END) AS [Debet Amount],
Sum( CASE WHEN [Posting Date] >= @fromDate AND [Posting Date] <= @toDate THEN [Credit Amount] ELSE 0 END) AS [Credit Amount],
Sum( CASE WHEN [Posting Date] <= @toDate THEN Amount ELSE 0 END) AS [Ending Balance],
Sum( CASE WHEN [Posting Date] >= @fromDate AND [Posting Date] <= @toDate THEN [Amount] ELSE 0 END) AS [Net Change]
FROM FA06data
GROUP BY [FA No], [FA Description]
Please help as early as you can.
Thanks,
NaveenThanks for your responce.
we are using Sql with the query designer.
what we can use? like calculated key figure. -
Bug average calculation in form?
Hye,
I made an editable form in acrobat XI for mac.
I set all the fields to number and the last field I want to calculate the average of all the other fields.
So I select the fields which average I want...
But upon testing, I'm getting impossible average calculations.
F.ex. testing several fields with value "9", returns me a "0,..." value, which is impossible...
How to solve?
ThanksIt's hard to say what's happening without seeing a sample. Can you post one somewhere? Unfortunately, you can't post one here, but can at Acrobat.com, dropbox, skydrive.com, etc.
-
Urgent!!Average calculation based on a characteristic!
Hi guys
I have an average calculation based on a characteritic ..
Example:
This is a SRM Mgmt.It has an Organisation purchasing org,source purchase,PR,etc..
Report is a Survey rpt.
Average Score across Customer responded for each question for the particular PR...
Where weightage is applied for each question & based on which
total weightage of all Qns for a PR
Avg.Score= -
No of Questions.
How do u calculate using the exception aggregation??????????Pls revert ASAP.
thnx
BI LearnerSolving Myself
Maybe you are looking for
-
HT4108 Unable to read a movie from my iPad to an external display
Hi everyone, I fear the worst here. I downloaded a TV show from iTunes and watched it fine on my external display (a full blown HD tv). Then I downloaded an HD movie from the iTunes store but my iPad2 says it's unable to play protected content. What
-
How can i get apps from my itunes to my iphone?
okayy so i want to get the facebook application on my iphone and i dont have the app store on my ipone.. soo how can i get the app from itunes to my phone for ffree? i have a windows computer and i have restrictions on my phone because i use it too m
-
To generate the scripts for SAP mappings: - From the Warehouse Module Editor menu, choose Module then Generate. - The Generation Mode dialog hi i don't find the "generation mode dialog". where i find it? robson thanks.
-
Lightroom CC will not run on my MAC OX Yosemite 10.10.3
Using the CC I download Lightroom cc and found the trial version will not run. I had a Lightroom 5 with 24 days left on the trial which I deleted - help
-
Authentication Problem - Specify the correect username or password
Hello dear software developers. I'm a newbie on WebCenter Portal. After installation parts, i try to run my first application according to this tutorial -> http://www.youtube.com/watch?v=Gc1Zdikx4sc Time of 4.54 in tutorial i entered user name and th