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: 
alexcastorena
Contributor III
Contributor III

Help with Trailing 12 months

Hello friends,

I'm reaching out for some help, I'm trying to get trailing 12 months based on the data below.
My most current period is 202009. Trailing 12 months should give me 201910 thru 202009. 
Any help in writing the set analysis is greatly appreciated.

FiscalPeriodSALES
201901               13,214
201902               14,353
201903               21,208
201904               13,478
201905               14,642
201906               22,104
201907               14,903
201908               15,546
201909               20,605
201910               15,974
201911               16,297
201912               22,911
202001               13,794
202002               14,364
202003               20,860
202004               14,926
202005               13,744
202006               19,176
202007               15,169
202008               15,491
202009               17,819
Labels (2)
6 Replies
Vegar
MVP
MVP

What if you try this expression: 


sum(aggr(rangesum(above( sum({<FiscalPeriod=>} SALES),0,12)),FiscalPeriod))

 

Vegar_0-1601407056794.png

 

alexcastorena
Contributor III
Contributor III
Author

hi Vegar,
i tried that, though it's showing more than 12 months. if possible i would like to select a fiscal period and have the data only show 12 months back from what was selected

Kushal_Chawda

@alexcastorena  Assuming your fiscal period is formatted as proper date using Date(Field,'YYYYMM') if not then first convert it and then you can try below

sum({<FiscalPeriod={">=$(=date(addmonths(max(FiscalPeriod),-11),'YYYYMM'))<=$(=date(max(FiscalPeriod),'YYYYMM'))"}>}
aggr(rangesum(above( sum({<FiscalPeriod=>} SALES),0,12)),(FiscalPeriod,(NUMERIC,ASCENDING))))

alexcastorena
Contributor III
Contributor III
Author

Hello Kush,

Unfortunately, the fiscal period that i was given is already in YYYYMM, no other date is available.
i tried this set analysis formula, but it only gives me data for 2020

sum({<FiscalPeriod={'>=$(=max(FiscalPeriod)-12)<=$(=max(FiscalPeriod))'}>}Sales)


Kushal_Chawda

@alexcastorena  did you try the full expression provided? Seems you are using just part of the expression.

alexcastorena
Contributor III
Contributor III
Author

i did try the formula you provided though it did not work