Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
pepe2209
Creator
Creator

avg of top ten percent of values within dimension

Hello I've searched a lot about retrieving the top ten percent, but this is almost always focused on limiting the table dimension to the top 10 percent records. I want something else, please look at the example (the # of records columns are just for explanatory purpose, I don't need them)

Dimenson: Quarter#records allavg result all#records top 10%avg result top 10%
Quarter 3 2015100151021
Quarter 2 2015110141119
Quarter 1 2015140151422
Quarter 4 2015100131019
Quarter 3 2015120161222
etc

So for each "quarter" I would like to calculate the avg of the top 10% records according to the field "result" and within the dimension.

Ypur help would be much appreciated.

Regards,

Peter

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I assume you need the key here if you don't want to aggregate equal results:

=Avg( TOTAL<quarter> Aggr( If( Rank( Sum(result),4,0) <= Count(TOTAL<quarter>result) / 10, Sum(result) ), quarter, key))

View solution in original post

4 Replies
swuehl
MVP
MVP

Maybe (would be easier to answer with a small sample QVW uploaded) something like

=Avg( TOTAL<Quarter> Aggr( If( Rank( Sum(result)) <= Count(TOTAL<Quarter>result) / 10, Sum(result) ), Quarter, resultID))

resultID is maybe just result, if you want to consider each single result record, and you don't need to group by another dimension.

as I said, these kind of questions will be a lot easier to answer with a more detailed explanation of your data model and data.

pepe2209
Creator
Creator
Author

I've added an example qvw, the data consists of only three fields: Key, quarter and result

Thanks for your help

swuehl
MVP
MVP

I assume you need the key here if you don't want to aggregate equal results:

=Avg( TOTAL<quarter> Aggr( If( Rank( Sum(result),4,0) <= Count(TOTAL<quarter>result) / 10, Sum(result) ), quarter, key))

pepe2209
Creator
Creator
Author

Awesome thanks!