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

Can I create a pivot table showing only top 3 employees with their previous year rank?

Hi is it possible to get a pivot table that only shows top 3 employees for current year but their rank from the previous year compared to the entire set of employees?

Example entire data set:

NameCurrent RankPrevious year rank
John1n/a
Joe21
Jim34
Jack4n/a
Jill52

 

What I want to get is:

NameCurrent RankPrevious year rank
John1n/a
Joe21
Jim34

 

What I am currently getting is :

NameCurrent RankPrevious year rank
John13
Joe21
Jim32

 

I am using an AGGR(IF(rank(sum({$<Year = {'$(=vMaxYear)'}>}Sales)))<=3,Name),Nameas my dimension.

And

=RANK(sum({$<Year = {'$(=vMaxYear)'}>}Sales))

=RANK(sum({$<Year = {'$(=vPriorYear)'}>}Sales))  as my expressions.

Can anyone help? @swuehl @Lisa_P 

Labels (3)
7 Replies
Saravanan_Desingh

I am assuming you have two tables like this.

tab1:
LOAD * INLINE [
    Name, Current Rank
    John, 1
    Joe, 2
    Jim, 3
    Jack, 4
    Jill, 5
];

Left Join(tab1)

tab2:
LOAD * INLINE [
    Name, Previous year rank
    John, n/a
    Joe, 1
    Jim, 4
    Jack, n/a
    Jill, 2
];
Saravanan_Desingh

Use Dimension Limit to Select the First 3.

commQV49.PNG

commQV50.PNG

If you have different Data Model, please let me know.

james227
Contributor II
Contributor II
Author

My data model is Employees, #sales, date.  So the ranks are not stored in the model and I'm using qlikview's rank function to derive them.  That's where I seem to have the problem because the ranks are relative.

Saravanan_Desingh

Can you share a sample data with Sales value and Date?

james227
Contributor II
Contributor II
Author

Sure,

LOAD * INLINE [
    Name, Sales, Year
    John, 100, 2020
    Joe, 80, 2020
    Jim, 60, 2020
    Jack, 40, 2020
    Jill, 20, 2020
    Joe, 100, 2019
    Jim, 20, 2019
    Julia, 60, 2019
    Jill, 80, 2019

];

Saravanan_Desingh

The below Script will help to create the Table with Ranks. Along with the Chart you can show the output.

tab1:
LOAD *, AutoNumber(RowNo(),Year) As Rank;
LOAD * INLINE [
    Name, Sales, Year
    John, 100, 2020
    Joe, 80, 2020
    Jim, 60, 2020
    Jack, 40, 2020
    Jill, 20, 2020
    Joe, 100, 2019
    Jim, 20, 2019
    Julia, 60, 2019
    Jill, 80, 2019
];

tab2:
LOAD Name, Rank As [Current Rank] 
Resident tab1
Where Year=2020;

Left Join(tab2)
LOAD Name, Rank As [Previous year rank] 
Resident tab1
Where Year=2019;

Drop Table tab1;

commQV55.PNG

NitinK7
Specialist
Specialist

Hi 

you can try below 

dimension-   Aggr(Only({<Year={'$(=Max(Year))'}, Sales={"=Rank(Aggr(Sum(Sales),Sales))<=3"}>}Name),Name)

expression -  Rank(Aggr(Sum(Sales),Year,Sales),4,1).

Capture.PNG

Thanks,

Nitin.