Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
rhyseretto
Contributor III
Contributor III

Sum sales only for dimensions that have sales from previous year

Hi there, here's what I'm looking to do. Imagine this data;

 

Product Year Sales
Apple 2021 $10
Banana 2021 $20
Carrot 2021 $15
Apple 2022 $15
Banana 2022

$20

 

If I do a simple table of '2022 vs 2021 year-to-date sales', I'll get;

 

Year Sales YTD
2021 $45
2022 $35

 

However, because I haven't received the carrot sales data yet, I don't want to include the 2021 carrot sales in this table. What can I do so that the 2022 sales omit anything where there isn't a 2021 sale for those dimensions? i.e., I want my table to read; 2021 = $30; 2022 = $35.

My assumption was I needed this;

 

if(Aggr(Sum({<[Year]=2021>}Sales),Year,Product)>0,
Aggr(Sum({<[Year]=2021>}Sales),Year,Product),0)

 

 

though this is just giving zeroes.

Many thanks!

Labels (4)
2 Replies
Digvijay_Singh

Not sure but this below expression work with the sample data - 

Aggr(Sum(if(Aggr(nodistinct Count(Year),Product)>1,Sales)),Year)

Digvijay_Singh_0-1645849738407.png

 

Vegar
MVP
MVP

You could also be able to solve this with set analysis without if(aggr(),aggr()). I would assume that solving using set analysis would be a more efficient method. 

A solution using set analysis could look something like this.

Sum( {<Product=P({<Year={"$(=max(Year))"}> Product})Sales)