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

Set analysis, FirstSortedValue & Aggr

Hi,

Sorry, it seems trivial, i read lot of topic, but i feel lost.

I have containers that contains categorized objects :

containerobject_idcat
C11A
C12B
C13A
C14A
C25B
C26H
C27H
C28D
C39E
C310E
C311A
C312H
C313E

 

I want the largest category for each container, it's ok :

 

 

=FirstSortedValue( cat, -aggr( count(object_id), container, cat))

 

 

 

container=FirstSortedValue( cat, -aggr( count(object_id), container, cat))
C1A
C2H
C3E

 

But if i use that in set analysis to count objects :  count( {<cat={"$(=  here )"} object_id) )

it doesn't work :

 

 

=count( {<cat={"$(=FirstSortedValue( cat, -aggr( count(object_id), container, cat)))"}>} object_id)

 

 

 

container=FirstSortedValue( cat, -aggr( count(object_id), container, cat))=count( {<cat={"$(=FirstSortedValue( cat, -aggr( count(object_id), container, cat)))"}>} object_id)
C1A0
C2H0
C3E0

 

(note : i'm not admin, unable to edit loading script)

Thanks for your help.

1 Solution

Accepted Solutions
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Julien,

Kudos to you - you are tackling very complex calculations for a newbie!

So, this calculation doesn't work in Set Analysis because it needs to be "sensitive" to the dimensions of your chart (such as Container), but Set Analysis cannot do that because it's evaluated once per chart, not once for each line of your chart.

The good news is that you don't need to insert this formula into your Set Analysis. You can simply use nested aggregation to calculate the max value of the count of objects for the highest category. As simple as this:

max(aggr(count(object_id), container, cat))

Let me invite you to my upcoming on-line session on Advanced Set Analysis and AGGR on November 18th. I will be teaching advanced analytical uses of Set Analysis and AGGR, and one of our hands-on examples deals exactly with your situation. You will learn a lot, I promise! See direct link in my signature below.

View solution in original post

3 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Julien,

Kudos to you - you are tackling very complex calculations for a newbie!

So, this calculation doesn't work in Set Analysis because it needs to be "sensitive" to the dimensions of your chart (such as Container), but Set Analysis cannot do that because it's evaluated once per chart, not once for each line of your chart.

The good news is that you don't need to insert this formula into your Set Analysis. You can simply use nested aggregation to calculate the max value of the count of objects for the highest category. As simple as this:

max(aggr(count(object_id), container, cat))

Let me invite you to my upcoming on-line session on Advanced Set Analysis and AGGR on November 18th. I will be teaching advanced analytical uses of Set Analysis and AGGR, and one of our hands-on examples deals exactly with your situation. You will learn a lot, I promise! See direct link in my signature below.

JulienQ
Contributor
Contributor
Author

Oleg,

Thank you so much. It was so obvious... you allowed me to step back.

In fact, the final goal it's to filter rows to keep only largest category by containers.

Based on your solution, this seems to be working :

=if(
	max(aggr(nodistinct count(object_id), container, cat))
    =
	max(total <container> aggr(count(object_id), container, cat))
    ,
    'keep'
)

Capture.PNG

(But i need to think about why  😅)

Thank you once again

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Julien,

You seem to be hitting many of the exercises from my Set Analysis and AGGR class, one by one. There is a number of possible solutions for limiting the table to N top performing elements. The one you came up with, is working, but I could offer a simpler one.

I can give you a hint - in your calculated dimension for a Category, use a single AGGR and a function Rank() to limit categories to only top ones per container.

I really hope that you can make it to my class on November 18th, you'll enjoy it!

Cheers,