Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Help! Nested Aggregation Sort

Hi,

I have an aggregation like this:

= concat( aggr(count(distinct ID_FIELD), TXT_FIELD),'|')

And I need the concatenation result to be in alphabetic order, so I tried this:

= concat( aggr(count(distinct ID_FIELD), (TXT_FIELD,(TEXT,A2Z))),'|')

Also I have tried something like this:

= concat( aggr(count(distinct ID_FIELD), TXT_FIELD),'|',TXT_FIELD)

And even this:

= concat( aggr(count(distinct ID_FIELD), (TXT_FIELD,(TEXT,A2Z))),'|',(TXT_FIELD,(TEXT,A2Z))

With no luck,can you please help me?


Thanks!

1 Solution

Accepted Solutions
swuehl
MVP
MVP

The Concat() function applies its own sort to the elements to be concatenated, that's why you can set a sort weight as third argument. If you don't set a sort weight, the elements will be sorted in alphabetical order, that's why your work around works like expected.

View solution in original post

5 Replies
Not applicable
Author

Hi Bruno,

I think your data would be something like this:

ID_FIELD|TXT_FIELD

11|abc

12|def

12|def

13|ghi

14|jkl

15|mno

15|mno

15|mno

14|jkl

13|ghi

13|ghi

14|jkl

14|jkl

15|mno

15|mno

and I guess you would want ouput as:

ID_COUNT|TXT_FIELD

5|mno

4|jkl

3|ghi

2|def

1|abc

You need to have 2 expressions in your chart object:

1. For ID_COUNT

=MAX(AGGR(COUNT(ID_FIELD),TXT_FIELD)))

Sort this expression field in descending order by value.

2. For TXT_FIELD

=FIRSTSORTEDVALUE([TXT_FIELD],-AGGR(COUNT(ID_FIELD),TXT_FIELD)))

Let me know if this helps.

vinieme12
Champion III
Champion III

Search for threads like Sortable AGGR

The sortable Aggr function is finally here!

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Anonymous
Not applicable
Author

Thanks for your answer, but I still can't find where my mistake is!

Anonymous
Not applicable
Author

Thanks for your answer, but I really need it to be in a single expression!

Also I don't have any dimensions in this chart, I'm using it do create an URL to download an image from Google Chart!

What I ended up doing was:

=keepchar(concat( aggr(TXT_FIELD&'-'&count(distinct ID_FIELD), TXT_FIELD),'|'),'0123456789')


Ugly, I agree.. but works!


But I still don't understand why this won't work:

= concat( aggr(count(distinct ID_FIELD), (TXT_FIELD,(TEXT,A2Z))),'|')

Thanks!

swuehl
MVP
MVP

The Concat() function applies its own sort to the elements to be concatenated, that's why you can set a sort weight as third argument. If you don't set a sort weight, the elements will be sorted in alphabetical order, that's why your work around works like expected.