Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Weighted Average as KPI Stat

All,

I am looking for some help on weighted averages. I have looked through the other examples on this site but cannot find one to match my query.

I have a list of companies with a market value held, target price and current price. What I want to do is to be able to show a one item key performance indicator that shows the weighted average total return for all stocks selected by the user.

I have attached the sample data in excel as well as my attempt to weighted average in the attached QVW.

Sample excel table shown below - the columns 'DB field' are in the excel file and are known. The 'calculation fields' are used to calculate the weighted average return.

DB FIELDSCALCULATION FIELDS
DESCRIPTIONAUMTargetCurrentExpd TRWeightWeighted TR
COMPANY A      392,674,46718.416.3712.4%60.3%7.5%
COMPANY B      258,514,7892.21.8220.9%39.7%8.3%
W AVG TR15.8%

I have been able to get to the point of calculating the market value weighted total return in a pivot table (listed as 'W AVG EXPD RTN' in the QVW) but I cannot work out how to

a) Sum this value within the pivot (partial sum gives a blank)

b) have the calculation bundled up into a separate field (e.g. Weighted Average Total Return text box in the attached QVW).

Really would appreciate help on this one - I have been struggling with this one for some time.

1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

If you simply want to  Sum your W AVG EXPT RTN, try this

sum(aggr(Sum((TARGET - CURRENT)/CURRENT)* SUM(MARKET_VALUE)/SUM(TOTAL MARKET_VALUE)), DESCRIPTION))

View solution in original post

6 Replies
Not applicable
Author

the fastest way is change the control from Pivot table to straight table and use "Sum" as the total Mode for that field.....

marcus_malinow
Partner - Specialist III
Partner - Specialist III

If you simply want to  Sum your W AVG EXPT RTN, try this

sum(aggr(Sum((TARGET - CURRENT)/CURRENT)* SUM(MARKET_VALUE)/SUM(TOTAL MARKET_VALUE)), DESCRIPTION))

Anonymous
Not applicable
Author

Thanks - but even as straight table I still get a '-' in the total column. When you say 'use sum as total mode' - what does this mean exactly, I cannot see this as an option, or do you mean creation of a custom label that is SUM(w avg column)

Also this would not answer my key issue to have a separate cell that consolidates the results

Anonymous
Not applicable
Author

Boom! That works a treat!! I cant thank you enough

Clearly I need to brush up on my understanding of the aggr function

Anonymous
Not applicable
Author

Marcus - could I ask for your assistance again here: as I have come to implement this fully I have hit a snag which seems to be breaking the formula, I cannot see why.

I am using the following formula in a table to get the correct weighted total return. The difference here is the change to the denominator - I needed to exclude the market value of holdings where there is no target price as this would otherwise skew the number when aggregated. The result is correct in the column is it in but as before there is no sum (as no aggr is being used at this stage presumably).

((Target - Current)/Current)*(SUM(MKT_VAL)/(SUM( TOTAL {$<Target = {'*'}-{''}>} MKT_VAL))

Implementing the same formula that worked earlier combined with the above I am getting crazy results

NUM(sum(aggr(Sum((Target - Current)/Current)*(SUM(MKT_VAL)/SUM( TOTAL {$<Target = {'*'}-{''}>} MKT_VAL)), DESCRIPTION)),'#.#%')

DESCRIPTIONTARGETPRICETOTAL RETURNMKT VALUE% AllWeighted AvgAggr FormulaMultiple Diff
1,722,421,335 -27.86%
COMPANY A120.00108.1510.957%1,181,628,84068.6%7.5168%60.13%         8.00
COMPANY B18.4016.3712.401%392,674,46722.8%2.8271%8.48%         3.00
COMPANY C96.00483.20-80.132%148,118,0298.6%-6.8909%-96.47%       14.00

Strangely, the 'wrong' result (total of -27%) is based on exact multiples of the correct weighted average on a line by line basis.

Can you see what I am doing wrong here?

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Ben,

can't see anything obviously wrong.

Perhaps adding a flag in the load to indicate a NULL Target value might help.

Alternatively if you upload another copy of your QVW someone might be able to help.

Marcus