Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
dandaanilreddy
Partner - Creator III
Partner - Creator III

Issue with top 3 values with same date

Hello All,

I'm facing issue with top 3 values when i have same date for 2 records. Below is the output am getting only 2 records.

I observed for 2021-03-31 i see there are 2 rows with different values. (300, 150)

Month namedateproductvalue
March2021-03-16Test1500
March2021-03-05Test2410
    

 

Expected output:

MonthnamedateCompanyvalue
March2021-03-16Test1500
March2021-03-05Test2410
March2021-03-31Test3300

 

Measure expression: if(aggr(sum(value)),Monthname,row)<=3,sum(value))

 

Thanks

1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

Not sure what row field is, so i switched it with date.  And i added rank parameter to break ties.

if(aggr(rank(sum(value), 1,1),Monthname,date)<=3,sum(value))

View solution in original post

6 Replies
PrashantSangle

can you provide data?

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
dandaanilreddy
Partner - Creator III
Partner - Creator III
Author

dateProductvalue
2021-03-16Test1500
2021-03-05Test2410
2021-03-31Test3300
2021-03-31Test3150
2021-03-16Test1100

 

Expected output:

dateCompanyvalue
2021-03-16Test1500
2021-03-05Test2410
2021-03-31Test3300
stevejoyce
Specialist II
Specialist II

is "row" actually a field name in your data model (unique identifier)?

Aren't you missing a rank function as well?  Your measure expression is just if sum(value) <=3.

You have more closing parenthesis then open, so something is wrong with your measure expressoin.

 

if(aggr(rank(sum(value)),Monthname,row)<=3,sum(value))

dandaanilreddy
Partner - Creator III
Partner - Creator III
Author

Hi Steve,

Sorry i missed the rank while typing. I have tried the same expression what you provided but its not giving me the correct result ( giving me only 2 rows) as my dates and products are repeating multiple times with different values.

stevejoyce
Specialist II
Specialist II

Not sure what row field is, so i switched it with date.  And i added rank parameter to break ties.

if(aggr(rank(sum(value), 1,1),Monthname,date)<=3,sum(value))

dandaanilreddy
Partner - Creator III
Partner - Creator III
Author

Hi Steve,

Thanks a lot. it worked 🙂