Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Ethel
Creator III
Creator III

FirstSortedValue for the two same values

Hello,

This is my formula for the age for employees. I need to to put the biggest age interval in the title. 

FirstSortedValue(Age,-aggr(max(aggr(avg(aggr(sum([HeadCount]),[Period], Age)), Age)), Age))

My problem is that for particular moment I have two ages(55-60 and 60-65 ) that have exactly the same number of people(33 people). Probably because of that my formula doesn't show anything. For all other cases it works fine. How should I improve it and say to show youngest age for example if there are two groups with the same number of people?

Thanks a lot in advance!

Labels (4)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Two options I know of:

1. Add the DISTINCT keyword to FirstSortedValue and let Qlik choose. I think it's the first one in load order.

2. Add some small bias to your FirstSortedValue parameter 2. For example, -(Age * .001)

I realize Age is a string you may have to do something like -(SubField(Age,'-',1) * .001)

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

4 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Two options I know of:

1. Add the DISTINCT keyword to FirstSortedValue and let Qlik choose. I think it's the first one in load order.

2. Add some small bias to your FirstSortedValue parameter 2. For example, -(Age * .001)

I realize Age is a string you may have to do something like -(SubField(Age,'-',1) * .001)

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

Ethel
Creator III
Creator III
Author

thank you!

Could you please show in the formula how it should be?

I tried both distinct and (SubField(AgeBand,'-',1) * .001) and it is not working.

Maybe I'm not using it correctly?

 

Thanks a lot in advance!

Ethel
Creator III
Creator III
Author

Thank you!! ! It worked! I had to add distinct to the age(first parameter).