Qlik Community

QlikView Layout & Visualizations

Discussion Board for collaboration on QlikView Layout & Visualizations.

Announcements
Qlik Analytics Tour 2020 Online. Begins August 10th. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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
Highlighted
Master II
Master II

Re: How to total Top N row (by sort date)

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)

Highlighted
Not applicable

Re: How to total Top N row (by sort date)

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

Highlighted
Creator III
Creator III

Re: How to total Top N row (by sort date)

Dear Rasark,

   Please find the attachment of application let me know.

Regards

Highlighted
Contributor III
Contributor III

Re: How to total Top N row (by sort date)

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

Highlighted
Master II
Master II

Re: How to total Top N row (by sort date)

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)