Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
avastani
Partner - Creator III
Partner - Creator III

Weighted Average not rolling up properly

I have weighted averages in my app and when I start to roll them up in dimensions the weighted averages are not working. Has anyone faced this issue? I compute the weighted average in script as x= SUM(A * B)/SUM(B).

The chart expression is Avg(x) and it is not giving me the right answer at higher dimensions. At the lowest level of detail and 2-3 dimensions up the numbers look fine but start skewing beyond that point.

4 Replies
johnw
Champion III
Champion III

Avg() is a simple average. So your chart is taking the simple average of some precalculated weighted averages. As you've found out, that doesn't work.

You need to do the weighting in the chart itself, not in the script. Your chart expression needs to be sum(A*B)/sum(B) in order for the weighted averages to roll up properly.

avastani
Partner - Creator III
Partner - Creator III
Author

that is correct, so I modified that and do sum(A*B) and sum(B) separately in the script and the sum(A*B)/sum(B) as a separate expression in the chart itself.

however, qlikview is still not reporting the right answers when rolled up for both of them.

in case 1 where I am do the sum/s in the script, it works fine at low levels but starts giving problems at higher levels of roll up say roll up 4 onwards

in case 2 it gives incorrect results when the rolled up values are broken at lower levels.

i know it is something really simple that i am missing but can't get what it is.

johnw
Champion III
Champion III

Not sure what to say. Sounds like it should work. Do you have an example of the problem that you could post?

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

why aggregate anything in the script? How about simply using the formula in the chart expression?

If you could post a sample, it would be easier to find out what else might be wrong...