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

Mode returns two top strings

I have a field, [Junk Food Eaten], that contains comma separated values. 

Date          Junk

1/1/2000 Candy, Chips

2/1/2000 Chocolate, White Bread, Soda

 

I tease out the counts using subfield

Subfield([Junk Food Eaten], ', ') as [Junk]

 

My problem is when I use mode([Junk]), if there are two strings with the same amount of occurrences, it is returning null.

What I would like is to be able to return both of the tied top results. 

 

Thanks,

Jacob

 

 

1 Solution

Accepted Solutions
sunny_talwar

Try this:

Concat(Aggr(
    If(Count(Junk) = Max(TOTAL Aggr(Count(Junk), Junk)), Junk)
, Junk), ',')

View solution in original post

4 Replies
Taoufiq_Zarra

Hi,

in case the occurrence is equal, so mode returns by default a null, what would you like the script to return?


on the example you put here, what is the output that you want?

Cheers,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
JacobJones
Creator
Creator
Author

Well if there were 5 instances of Candy and 5 of Chips and they were both the most frequent occurrence, of like it to return Candy, Chips

sunny_talwar

Try this:

Concat(Aggr(
    If(Count(Junk) = Max(TOTAL Aggr(Count(Junk), Junk)), Junk)
, Junk), ',')
JacobJones
Creator
Creator
Author

Thank you so much, that does it!