Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
Not sure but this below expression work with the sample data -
Aggr(Sum(if(Aggr(nodistinct Count(Year),Product)>1,Sales)),Year)
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)