Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Our next Qlik Insider session will cover new key capabilities. Join us August 11th REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
rsark
Contributor III
Contributor III

How to total Top N row (by sort date)

Hello,

I am attempting to create a expression to sum total quantity for top N in list.   I have attempted to use the Rank, Aggr, Presentation Max Number setting and I am not having any luck.  Any suggestions and/or assistance would greatly be appreciated.    (see attached .QVW with sample data detail and expected results)

Regards, 

Ron

5 Replies
whiteline
Master II
Master II

Hi.

You can use set analysis with rank, but you'll need some key field to perform this (I've used PDate as it's different for eachrow).

For top 5 sum:

=sum({$<PDATE={"=Rank(total sum(PQTY))<=5"}>}PQTY)

Not applicable

Hi.

I used the whiteline expression and I made a little change.

The expression

=sum( {<PCODE= p({$<PCODE={"=Rank(sum(PQTY))<=5"}>}) >} PQTY)

show the sum for the 5 tops PCODE.

Alessandro Furtado

shaik_basha
Creator III
Creator III

Dear Rasark,

   Please find the attachment of application let me know.

Regards

rsark
Contributor III
Contributor III
Author

Hello All,

The Whiteline approach would work great (Thanks)  if I was looking to rank QTY, but the requirement is to rank/sort the PDATE and sum the QTY by Top N

Sort/Rank the date in descending order for the current selection and sum the QTY for the Top N.  The repsonse Shaik  submitted was close, but the RowNos were loaded via script and the production load will be over 150,000k rows...

Thanks,

Ron

whiteline
Master II
Master II

Sort/Rank the date in descending order for the current selection and sum the QTY for the Top N.

I think it's even easier:

=sum({$<PDATE={"=Rank(total ONLY(PDATE))<=5"}>}PQTY)