Focal Point
[CLOSED] Weighted Averages

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3261002961

May 24, 2006, 10:28 AM
wfsharon
[CLOSED] Weighted Averages
I'm drawing a blank here ..

I need to calc weighted averages based on 2 columns

Amount Return
9,500,000 14.4%
4,750,000 15.0%
3,963,600 22.5%
11,115,000 14.9%
------------------------------------------------
29,328,600 15.77%

I'm sure this is pretty basic, but it's been a while since I've had my WF hat on! I can certainly sum the Amount column, but it's the weighting of the Return that has me stymied.

Each Return value is multiplied by it's corresponding Amount. The sum of these products is then divided by the sum of the Amount column.

A DEFINE? A RECAP? A COMPUTE?

TIA...

This message has been edited. Last edited by: Kerry,
May 24, 2006, 10:59 AM
Prarie
Yes do some searches on RECAP. Should be what you need.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
How about this...

TABLE FILE CAR
PRINT
DEALER_COST
RETAIL_COST
COMPUTE MARKUP_PCT/D7.2% = (RETAIL_COST - DEALER_COST) / DEALER_COST * 100;

ON TABLE RECOMPUTE AND SUB-TOTAL
END

Sean


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
Perhaps we're getting close.

What I need to show as the final result is something like this:

Amount (A) Return (B)
------------ ----------
9,500,000 14.4%
4,750,000 15.0%
3,963,600 22.5%
11,115,000 14.9%
----------------------------
29,328,600 (C) 15.77% (D)

(C) is the sum of (A)
(D) is the sum total of each product (A)*(B), which is then divided by (C) to obtain the correct weighted average return. We can't calculate this until the total amount is known. It is similar to how one would calculate this in Excel, using the =SUMPRODUCT() function.

I'll need to brush up on knowing which WF keywords operate on data as it is retrieved vs when all is retrieved.

Thanks, all. Keep the good advice coming!
I'm not sure how this technique would not solve your problem. You need a formula that is COMPUTEd in the TABLE FILE section, which identifies how your Return is derived.

Then the ON TABLE RECOMPUTE AND SUB-TOTAL will total all of your Amounts, and recalculate a weighted (total) Return based on the COMPUTE formula.

Let me know if I am missing something here.

Sean


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
i agree with smiths, if B results from a COMPUTE statement in your fex, then ON TABLE SUMMARIZE
or ON fieldname RECOMPUTE
will recrank the proper result.
How is your B determined? Is B static or is it COMPUTEd in your fex?
You would want to COMPUTE your field, and very specifically not DEFINE it; A static, or DEFINEd field won't recompute easily

This message has been edited. Last edited by: susannah,




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
Hi Bill,

You need a defined field that multiplies A * B, then in your table request, sum the field, and then compute a new field that divides the defined field by A. I have an example if you want to see it.

Jen


Release 5.2.4
Upgrading to 7.6
Actually I think your missing a step in the methodology to calculate your weighted average return. The example should be more like the following.

Amount (A)...........Return (B)................... Weight(E) .................. Contribution (F)
----------------------------------------------------------------------------------------------- 9,500,000................14.4%............9,500,000/29,328,600...............0.046644
4,750,000................15.0%............4,750,000/29,328,600...............0.024294
3,963,600................22.5%............3,963,600/29,328,600...............0.030408
11,115,000...............14.9%............11,115,000/29,328,600..............0.056468
--------------------------------------------------------------------------------------------
29,328,600 (C)...............................................................15.77% (D)


D would be the sum of column F, which is E * B. The computed field needs to be the Amount row value divided by the total of column A.

Hope that helps. Sorry about the dots.

This message has been edited. Last edited by: MTracker,
I have the the same issue, but the result needs to be displayed as

Amount(A).... Return(B)
------------------------
9,500,000 14.4%
4,750,000 15.0%
3,963,600 22.5%
11,115,000 14.9%
------------------------
29,328,500(C) 15.77%(D)

without displaying the Weight(E) and Contribution(F) used for calculations..display (D) in place of total of Return(B) in the same line..

I tried use Subtotal/Recompute nothing seemed to work.. Tried using FML but that decreased the performance drastically..

I there any other way the output can be displayed as above...

Thanks in advance..


Release: Webfocus 7.6.11
OS/Platform: Windows
Output: HTML, EXL2K