Get sum of largest (by some value) 'x' rows via an expression
I have a table with cArticle, dSum and some other (irrelevant) fields. Let's say I created a QlikView table with theese two columns and a regular rank:
Now I want to get a sum(dSum) for largest (or smallest or whatever) 'x' rows, where x is a variable. How do I do that? I managed to display such sums in a table:
,IF(aggr(rank(sum(dSum)), cArticle) <= 6 and aggr(rank(sum(dSum),0,2), cArticle) > 3 ,'GroupB'
,IF(aggr(rank(sum(dSum)), cArticle) > 6,'GroupC'
)))
and sum(dSum) as an expression (I only used '3' and '6' numbers for convinience, those should be variables).
But I still can't calculate those sums in a single expression (to show in a text field for example), or apply different math operations based on different rank of cArticle
When I try to add a column to the last table, it takes rank of the group as a rank, not cArticle's rank as I want
So again, how do I get a sum of largest (or smallest or whatever) 'x' rows, where x is a variable?