Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
rohanmayekar
Partner - Contributor III
Partner - Contributor III

Sum of Top N records with positive value

Hi,

I have created sample table to support my qn.please see below.

I need to calculate sum of top 7 & bottom 7 DIffSalary and compare against total Positive values .

i am using following expression but not getting the desired result,

Top 7:

=sum({<Name={"=rank(sum(DiffSalary))<=7"}>} DiffSalary)

Bottom 7 :

=sum({<Name={"=rank(sum(DiffSalary))>$(=Max(aggr(rank(sum(DiffSalary)),Name))-7)"}>}DiffSalary)

Note: While calculating top 7 value i need to exclude negative values.

    

    

NameSTDSalary ActualSalaryDiffSalary
Josh20203000980
James70007500500
Ron65007100600
may50005100100
Lois27002901201
rock990100111
jaimey990878-112
Lisa900800-100
diana17671600-167
hamosh20001800-200
ali1200980-220
wilfred13001000-300
kusaick65006000-500
kamran1200987-213
daisy23231200-1123
linda2000200-1800
alex1789915000-2899
8 Replies
sunny_talwar

Both expression don't work or just the bottom one doesn't work?

sunny_talwar

For bottom, you can try this

=sum({<Name={"=rank(-sum(DiffSalary)) <=7"}>}DiffSalary)

Anonymous
Not applicable

For top 7 excluding negatives try


=if(ActualSalary-STDSalary>0,sum({<Name={"=rank(sum(DiffSalary))<=7"}>} DiffSalary))



rohanmayekar
Partner - Contributor III
Partner - Contributor III
Author

Not working.

rohanmayekar
Partner - Contributor III
Partner - Contributor III
Author

Hi,

The condition check before calculating Top10 and bottom 10 is as below,

1) IF actual- standard is positive => what are my top 10 salaries

2) IF actual- standard is negative=> what are my bottom 10 salaries

Anonymous
Not applicable

Adding to sunny's suggestion :

=sum({<Name={"=rank(ONLY({1}(-sum(DiffSalary))) <=7"}>}DiffSalary)

rohanmayekar
Partner - Contributor III
Partner - Contributor III
Author

This does not work

rohanmayekar
Partner - Contributor III
Partner - Contributor III
Author

Hi All,

Following expression giving error,

=sum({< STDSalary-ActualSalary = {">=0"} >}STDSalary-ActualSalary)