Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
hhajjali
Contributor III
Contributor III

Average of last 5 better results from the 6 last results

Hello,

Here is my problem, I have a table as follow:

ID RESULTS
15
28
37
45
58
69
75
84
910
102

I need to calculate the average of the last 5 better results from 6 last results. In my case a the smaller the result is the better.

So in the example above, the 6 last results are results with ID 5 to 10. The best 5 are IDs: 10, 8, 7, 6 and 5.

The average will be (2+4+5+9+8)/5 = 5.6.

ID is always incremental.

Thanks for your help.

Regards.

1 Solution

Accepted Solutions
OmarBenSalem

with this:

if(rank(aggr(sum({<ID={">=$(=max( all RESULTS)-5)"}>}RESULTS),ID))>1,sum(RESULTS))


U'd have this:

Capture.PNG

For the Average, use a KPI object with this expression:

AVG({<ID={"=rank((sum({<ID={'>=$(=max( all RESULTS)-5)'}>}RESULTS)))>1"}>}RESULTS)


Result:

Capture.PNG

View solution in original post

3 Replies
sunny_talwar

Why is there no 9 in best 5? and two 8s?

OmarBenSalem

with this:

if(rank(aggr(sum({<ID={">=$(=max( all RESULTS)-5)"}>}RESULTS),ID))>1,sum(RESULTS))


U'd have this:

Capture.PNG

For the Average, use a KPI object with this expression:

AVG({<ID={"=rank((sum({<ID={'>=$(=max( all RESULTS)-5)'}>}RESULTS)))>1"}>}RESULTS)


Result:

Capture.PNG

hhajjali
Contributor III
Contributor III
Author

Thanks for your help