Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
BiancaWou
Contributor
Contributor

Result of previous year in a aggr(only()) function

I have this function including aggr and only

sum(aggr(only({<InstalledBaseFlag={1}, InstalledBaseType -={DeinstallNew}>}_InstalledBaseCumul), MonthYear, InstalledBaseType, ProdHier1, SoldTo, Region, Product))

This formula gives me the result of the selected Month and Year, example April 2023

Now, I would like to compare this with the result of the previous year (selection will still be April 2023, but I would like to see the numbers of April 2022 with the function AddMonths -12

If I use this formula

sum(aggr(only({<<MonthYearNum=
"$(=Num(Max(AddMonths(MonthYearNum,-12))))"},Year=,Month=,MonthYear=,Day=,YTD,InstalledBaseFlag={1}, InstalledBaseType -={DeinstallNew}>}_InstalledBaseCumul),
MonthYear, InstalledBaseType, ProdHier1, SoldTo, Region, Product))

I get no result

 

This formula without the aggr() is working(but incorrect), but when I add the aggr and only, it is not working

sum({<MonthYearNum={"$(=Num(Max(AddMonths(MonthYearNum,-12))))"},Year=,Month=,MonthYear=,Day=,YTD,InstalledBaseFlag={1}, InstalledBaseType -={DeinstallNew}>}_InstalledBaseCumul)

 

How can I get from this formula

sum(aggr(only({<InstalledBaseFlag={1}, InstalledBaseType -={DeinstallNew}>}_InstalledBaseCumul), MonthYear, InstalledBaseType, ProdHier1, SoldTo, Region, Product))

to the result of the previous year (when selected a year and a month)

Thanks,

Bianca

Labels (1)
2 Replies
Chanty4u
MVP
MVP

Try this 

sum(aggr(

    only({<InstalledBaseFlag={1}, InstalledBaseType-={DeinstallNew}, MonthYearNum = {"$(=Num(Max(AddMonths(MonthYearNum, -12))))"}>}_InstalledBaseCumul),

    InstalledBaseType, ProdHier1, SoldTo, Region, Product

 

))

BiancaWou
Contributor
Contributor
Author

Dear Chanty4u

Thank you for the formula.

This is working, but only if you also select the previous year. (2023 + 2022)

If you only select 1 year and 1 or more months, you get no result (0)

 

Bianca

 

if