Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

aggregate by maximum year in dataset

Hi,

I have been following the forum questions on using set expressions and $-sign expansions to aggregate a field where it meets a particular condition.

For example, I want to count the number of IDs for the latest/maximum year in dataset. I wrote the following script:


count({<current_year={'$(=Max(Date(Date#(Year(date#),'YYYY')), 'YYYY'))'}>}id)

but it returns the count of ids across all years (there are two years of data in my data set) instead of max year.

I have field called year# and date# in my data set.

What I also don't  understand that for my code to return a number, I have to create this current_year variable. I assumed that logically the code be written so  that that year# equals the max year value, the count of ids, like this.

count({<year#={'$(=Max(Date(Date#(Year(date#),'YYYY')), 'YYYY'))'}>}id)

I am new to the Qlik community and have gone through related posts, but still confused by my code behavior.

Any help is appreciated.

2 Replies
Anil_Babu_Samineni

May be you places wrong place/? May be just this

count({<year#={'$(=Max(Year([date#])))'}>}id)


Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
shiveshsingh
Master
Master

may be this

=count({<Year = {'$(=max(Year(DateField))'}>}Ids)