Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
beck_bakytbek
Master
Master

Sum of 3 previous periods

Hi Folks,

i have got a table (my example):

Period 1 2 3 4 5
MyValues 10 15 40 55 70
Expected Output:
sum of 3 previous periods
10 25 65 110 165

 

my expected output is: how can i calculate the sum of 3 previous periods in script?

i can solve this issue by using this expression on Userinterface as expression:

sum(aggr(rangesum(above(sum(MyValues),0,3)),Period))

 

but i want to know, how i can transfer this expression in script?

Does anybody have any idea? Thanks a lot Bek

 

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

You need an appropriated sorted resident-load and within it something like:

rangesum(Field, peek('Field', -1), peek('Field', -2)) as X

Further you may need some if-loops to check which records are the first/second per your key-field(s) to adjust the measure to just take the current respectively the current and the previous value. And of course if there are multiple values per Field you need to aggregate them in beforehand - again with the right group by dimensions and any filters if needed.

View solution in original post

2 Replies
marcus_sommer

You need an appropriated sorted resident-load and within it something like:

rangesum(Field, peek('Field', -1), peek('Field', -2)) as X

Further you may need some if-loops to check which records are the first/second per your key-field(s) to adjust the measure to just take the current respectively the current and the previous value. And of course if there are multiple values per Field you need to aggregate them in beforehand - again with the right group by dimensions and any filters if needed.

beck_bakytbek
Master
Master
Author

Hello Marcus,

sorry for late responce, thank you very much for your time and help