Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Ajaj
Contributor
Contributor

Variable by dimension in Aggr

I have the following data and expression :

test:
LOAD *
inline
[
year,code,X
2020,'A',10
2021,'A',7
2019,'C',25
2020,'C',50
];

sum(
Aggr(
sum({<year={$(=max(year))}>}
X
)
,code
)
)

I want the sum of X for the max year grouped by code.

For example here I want 7 + 50 = 57.

Unfortunately my expression gives me 7 

How can I tell the variable $ to take the aggr group into account ?

Thanks you,

 

1 Solution

Accepted Solutions
maxgro
MVP
MVP

try with

sum(aggr(if(max(TOTAL <code> year)=year, sum(X)), code, year))

View solution in original post

2 Replies
maxgro
MVP
MVP

try with

sum(aggr(if(max(TOTAL <code> year)=year, sum(X)), code, year))

Ajaj
Contributor
Contributor
Author

Nice, it works perfectly,

Thanks