简体   繁体   中英

Spotfire - sum() over lookback

I'm trying to sum the values in a column VAL for the last 14 days from T_DATE, by account.

My expression is

if([RND_FLG]=1 ,Sum([VAL]) over (Intersect([T_ACC],LastPeriods(14,[T_DATE]))),null)

9/10 the results are accurate, but this is not always the case.

Any help is appreciated.

Sample data below:

ALLDATE     T_ACC       VAL     14DAYVAL  
12/13/2016  1501313137  500000  500000  
12/15/2016  1501313137  800000  1300000  
12/19/2016  1501313137  500000  1800000  
12/20/2016  1501313137  500000  2300000  
12/21/2016  1501313137  500000  2300000  
12/22/2016  1501313137  500000  3300000  
12/30/2016  1501313137  200000  3500000

You are probably getting incorrect results when you have gaps in your dates. LastPeriods() isn't the same as n - days so it's aggregating over n number of rows versus days. You can normalize your data to have 1 row per date to get around this.

尝试添加一个排名列,如 Rank([T_DATE],[T_ACC]) 然后你可以使用 over intersect 和 lastperiods 求和

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM