Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Aggregation over sub dimensions

  1. Greetings.

I have a feeling the answer involves the Aggr() function; however, as yet I can not get it to work.

I have a table similar to the example below

Order #SKULead time (days)Rank
1693391112703

169339

2231

111

6
16933934511418

169339

35661669

169339

8582895

178040

1112581
1780402231714
1711931112602
17811111121217

I can perform ranking and averaging etc on the table when I have one SKU selected, but when the selection is removed the ranking and average refers to all data displayed in that column (as shown above).

What I want to achieve is have an unfiltered table but show the ranking etc per SKU.

For example:

Order #SKULead time (days)Rank
1693391112703

169339

2231

111

2
16933934511411

169339

35661661

169339

8582891

178040

1112581
1780402231711
1711931112602
17811111121214

Please can anyone help?

12 Replies
Not applicable
Author

Hi Anbu

Thank you for your help. I am looking in the QlikView help file but can't yet figure out how your solution works.  As I am trying to learn from this could you briefly explain how this expression works?

Am I right in thinking that this:

aggr(rank(-[Lead time (days)]),SKU,[Lead time (days)])

returns the ranking, while the rest of the alt() and above() have been used to fix the sort order??

Thanks and kind regards

Oli

anbu1984
Master III
Master III

aggr(rank(-[Lead time (days)]),SKU,[Lead time (days)]) 

- Aggr on SKU,[Lead time (days)] creates a table like below in memory. Aggr is used to ignore your other dimension Order # while ranking


SKULead time (days)
111270
2231

111

3451141
3566166
858289
111258
223171
111260
1112121

- Then Rank is calcuated on [Lead time (days)] based on above data. 

Lead time, Rank

58, 1

60, 2

70, 3

121, 4


Rank of negative Lead time

Lead time, Rank

-58, 4

-60, 3

-70, 2

-121, 1


Alt( expr, Above(expr)) - Alt returns value of expr which provides non-null value. In our case, Rank generates null value, if you have same Lead times. So Alt is used to return to same rank from the above row

anbu1984
Master III
Master III

Generating rank in script

Initial:

LOAD [Order #],

     SKU,

     [Lead time (days)],

     [Desired result]

FROM

(biff, embedded labels, table is Sheet1$);

NoConcatenate

Final:

Load *,If(SKU = Previous(SKU) And [Lead time (days)] = Previous([Lead time (days)]),Peek(Rnk1),Rnk) As Rnk1;

Load *,AutoNumber(RecNo(),SKU) As Rnk Resident Initial Order by SKU,[Lead time (days)];

Drop table Initial;