Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Qlik1_User1
Specialist
Specialist

Fetching latest records top 2

Hi All,

below is sample data, need to get the latest 2 records as per date in chart..i don't want to make use of back end scripting for this as i need all the records , only in this chart want to show top 2 records

 

Need to fetch Top 2 latest date data for Product A

 

ProductOrder dateSalesCountry
A12/12/201710India
A10/10/201720Japan
A1/2/201930US
A10/17/201740Canada
B10/27/201950India
B1/3/202060Japan
B4/4/201870US
B5/12/201880Canada
B7/10/202190Japan
B5/11/2020100US

 

Expected Output

A30US
A10India

in chart only Product,Country and SUM(sales) needs to be displayed

Below is the expression I am using but its give 0 as a result

sum({<[Order date]={"=rank([Order date])<=2"},Product={'A'}>}Sales)

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Put your product condition within the rank(), like:

 

sum({<[Order date]={"=rank(if(Product='A', [Order date]))<=2"}>}Sales)

View solution in original post

6 Replies
settu_periasamy
Master III
Master III

Hi,

This expression is working fine for me.

=sum({<[Order date]={"=rank([Order date])<=2"},Product={'A'}>}Sales)

2020-02-16_12h12_10.png

Qlik1_User1
Specialist
Specialist
Author

It seems you have made selections in Product column for value A.

When I am using this same expression I am getting 0 records , I am doing it in Qlik sense

tresesco
MVP
MVP

Put your product condition within the rank(), like:

 

sum({<[Order date]={"=rank(if(Product='A', [Order date]))<=2"}>}Sales)

Qlik1_User1
Specialist
Specialist
Author

Thanks a lot it worked 🙂

settu_periasamy
Master III
Master III

Yes. Forgot to deselect.

Qlik1_User1
Specialist
Specialist
Author

Thanks for the help 🙂