Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

aggr function inside set analysis not working

Hello,

I have the following dataset:

BOOKSUBJECT BOOKNAME PUBLICATIONYEAR             

A                             Book1                   2011                                      

B                             Book2                   2010                                      

C                             Book3                   2010      

D                             Book1                   2011      

A                             Book5                   2008      

B                             Book2                   2009

I’m attempting to derive the minimum PUBLICATIONYEAR year for each BOOKSUBJECT.  I was able to do this as its own formula (in its own column in a straight table)

aggr(min(PUBLICATIONYEAR),BOOKSUBJECT)

However when I attempt to set that minimum PUBLICATION YEAR value into Set Analysis to count how many BOOKNAMEs have that BOOKSUBJECT only in that minimum/first year, it ignores the per row/BOOKSUBJECT value and just takes the minimum PUBLICATIONYEAR for the entire data set.  Here is as close as I got….

count({<PUBLICATIONYEAR = {"=$(#=min(aggr(min(PUBLICATIONYEAR), BOOKSUBJECT)))"} >}BOOKNAME)

So for the dataset above, when I attempt to count BOOKNAMES per BOOKSUBJECT for the minimum PUBLICATIONYEAR, I get a value of 2008 for *all* BOOKSUBJECTS even though I’m trying to get 2008 for BOOKSUBJECT A, but 2009 for BOOKSUBJECT B, etc…

Any ideas?

11 Replies
Not applicable
Author

I tried this and I get mostly zeros... I figured out a 'dirty' workaround.   The PUBLICATION YEARS only go back 5 years, so I was able to use nested IFs to check to see which year the the publications started for each term and then count the BOOKNAME for that year as the 'minimum'.

if(count({<PUBLICATIONYEAR = {"<=$(=min(PUBLICATIONYEAR)+1)"} >}BOOKNAME) > 0 , count({<PUBLICATIONYEAR = {"<=$(#=min(PUBLICATIONYEAR)+1)"} >}BOOKNAME))  ,

if(count({<PUBLICATIONYEAR = {"<=$(=min(PUBLICATIONYEAR)+2)"} >}BOOKNAME) > 0 , count({<PUBLICATIONYEAR = {"<=$(#=min(PUBLICATIONYEAR)+2)"} >}BOOKNAME))  ,

if(count({<PUBLICATIONYEAR = {"<=$(=min(PUBLICATIONYEAR)+3)"} >}BOOKNAME) > 0 , count({<PUBLICATIONYEAR = {"<=$(#=min(PUBLICATIONYEAR)+3)"} >}BOOKNAME))  ,

if(count({<PUBLICATIONYEAR = {"<=$(=min(PUBLICATIONYEAR)+4)"} >}BOOKNAME) > 0 , count({<PUBLICATIONYEAR = {"<=$(#=min(PUBLICATIONYEAR)+4)"} >}BOOKNAME))  ,

if(count({<PUBLICATIONYEAR = {"<=$(=min(PUBLICATIONYEAR)+5)"} >}BOOKNAME) > 0 , count({<PUBLICATIONYEAR = {"<=$(#=min(PUBLICATIONYEAR)+5)"} >}BOOKNAME))  ,

count({<PUBLICATIONYEAR = {"<=$(#=min(PUBLICATIONYEAR))"} >}BOOKNAME)

Not applicable
Author

Clearly In this case SET Analysis wont work because SET analysis work on entire table not row level. In this case the Min Year change every row.